Home Assistant - Automatically turn on / turn off bluetooth on your smartphone
Emiliano Guerzoni
Project Manager / Technical Manager renewables/energy efficiency projects | Demand Manager digital energy domain at algoWatt
Good sunday guys,
In this article we saw how to turn on / turn off manually the bluetooth on your smartphone.
Today we'll learn how to create an automation to do this for us.
Use case
Your smartwatch is connected via bluetooth to your smartphone but, if for some reason you don't have the smartwatch on your wrist, keeping bluetooth enabled on your smartphone is useless as well as probably a cause for an undesired battery's consumption.
Software configuration
Home Assistant code / procedure (yaml)
Add the entity sensor.yoursmartphone_bluetooth_connection to your dashboard.
This entity provides the attribute connected paired devices that refers to the list of paired devices that are currently connected:
领英推荐
When the smartwatch is not connected to your smartphone the list will be empty.
Taking into the account the behaviour described above, we can configure an auotmation to automatically turn off the bluetooth according to this trigger.
This is the piece of code you have to write down:
alias: Smartphone - Automatically disable bluetooth if not connected to my smartwatch
description: Smartphone - Automatically disable bluetooth if not connected to my smartwatch for one minute
trigger:
? - platform: template
? ? value_template: >-
? ? ? {{state_attr("sensor.yoursmartphone_bluetooth_connection",
? ? ? "connected_paired_devices") == [ ]}}? ?
? ? for:
? ? ? hours: 0
? ? ? minutes: 1
? ? ? seconds: 0
? ? ? milliseconds: 0
condition: []
action:
? - service: notify.mobile_app_yoursmartphone
? ? data:
? ? ? message: command_bluetooth
? ? ? data:
command: turn_off
mode: single
Some specifics about the code above
Thank you for reading. ?? I do hope you have enjoyed this article.
I'm available for any feedback so, feel free to contact me or share your thoughts in the comments section below!
Meanwhile,?if you liked this article share it or?subscribe?to my newsletter?about?Home Assistant?to read previous episodes and still up to date on latest news.
Student at Ebony state university
4 周https://ugamasontech.com/2024/10/29/how-to-fix-bluetooth-automatically-turning-on-in-android/
Civil Contingencies Advisor at Met Office
1 年slight tweak needed in your code - i needed the 3rd from last line to read "data:" rather than "data" to get it working. All good now though and it's a great tip - thanks