I’d like to create an automation however I just can find the correct way of doing so:
First things first these entities are involved:
switch.tv_livingroom ( states on or off \ can turn on or off the tv)
sensor.tv_livingroom ( states on or standby)
media_player.kodi_livingroom
The “sensor.tv_livingroom” triggers a remote cec request to get the current state of my tv what I would like to do is first if the sensor changes I’d like to set the “switch.tv_livingroom” switch to match the status without sending the actual switch command so I get a consistent user interface.
I’d like to trigger the switch.tv_livingroom if “media_player.kodi_livingroom” changes to playing.
and last
I’d like to turn off the tv with switch.tv_livingroom if “media_player.kodi_livingroom” changes to stop however a slight delay of let’s say a minute or two would be good here.
I’ve read through the documentation but I’m struggling with the automations if anyone has the time to help that would be greatly appreciated.
I don’t quite understand the sensor.tv_livingroom part you are trying to do but it’s late and I need to go to bed so probably reading comprehension failure on my part.
Thanks a lot I’ll give that a shot, with the sensor I meant that I have a sensor which detects the state of my TV e.g. on and standby I also have a switch to turn it on or off which I wanted to match of the sensor state changes. This is what I’ve come up with which seems to work any improvements let me know:
- alias: Kodi Livingroom CEC power switch ON
hide_entity: true
trigger:
- platform: state
entity_id: sensor.tv_livingroom
to: 'on'
from: 'standbye'
action:
service: homeassistant.turn_on
entity_id: switch.tv_livingroom
- alias: Kodi Livingroom CEC power switch off
hide_entity: true
trigger:
- platform: state
entity_id: sensor.tv_livingroom
to: 'standbye'
from: 'on'
action:
service: homeassistant.turn_off
entity_id: switch.tv_livingroom
One last thing is there any call to stop playback on kodi without switching off the device? Or do I need a command line toggle and call the API?
PS. if you wonder why I don’t use the HDMI-CEC component the CEC client is a remote device and accessed via ssh
Cheers
Tops! I think those automations are straight adaptations from the examples and cookbooks but for other use cases. Have a look at this one and see if it looks familiar.
I don’t think it matters but instead of using homeassistant.turn_on or .turn_off for the domain in the service part of the action you might use the specific domain, - switch, scene, light, group and another handy one as you have found is media player. This opens up a few more command options when you use a device specific domain.