Greetings to everyone on this awesome community. I have been browsing the forum for quite a while and have found answers to almost every one of my questions, as a rookie in home assistant, until now.
So, here is the situation.
I have a Mikrotik router, and have the Mikrotik Router integration (the HACS one, as the official is inconsistent as hell) for presence detection.
I also have a chep generic “smart” TV, connected to the network, so the TV can be tracked whether it is ‘home’ (turned on and connected to the network) or ‘not_home’ (turned off and not connected to the network).
I have a broadlink rm4 universal remote, that I trained with basic commands to control the TV, like turning it on/off.
The goal is to create a toggle switch, that, when pressed, either direction, to activate the script that sends the power on InfraRed command to the TV, but to get its state (if its on the right or the left) based on whether the device tracker sees the TV as ‘home’ or ‘not_home’.
So far, i have created this binary sensor:
binary_sensor:
- platform: template
sensors:
arielli_tv_power_status:
friendly_name: Arielli TV Power
icon_template: >
{% if is_state('device_tracker.android_ef0c4c27bdbb2d2d_2', 'home') %}
mdi:television
{% else %}
mdi:television-off
{% endif %}
value_template: "{{ is_state('device_tracker.android_ef0c4c27bdbb2d2d_2', 'home') }}"
The sensor gets it’s state from the device tracking of the TV.
I have created a button in lovelace that gets its state from the above binary sensor, and when pressed, runs the script to send the appropriate IR command. However its just a simple press button, with its action programmed to call the service to run the script. The icon updates based on the sensor state, but its not a toggle.
So far this works good enough, but, since I’ve been messing around quite a while, I would prefer to keep things in a more organized and elegant way. So I would like to create an entity that is a toggle switch, getting its state from the binary sensor, and when pressed, to activate the same script, regardless of the state it is in.
I hope I made it clear enough. Thank’s in advance.