EDIT: TLDR, any ideas why this statement works in the template editor, but not in the automation?
{% if states.media_player.kodi_kodipilocal.attributes.media_content_type == 'movie' %}
The automation triggers, but it picks the else-case.
OP:
I want to have an automation turn off the light when I start playing in kodi. But only if it’s a movie.
I got it to work when trigger was “to: playing” and a template-condition in double curly brackets.
Now I have so many automations so I don’t want one for playing and one for stop, so I wanted to merge them into one automation, without condition and instead use service_template, and there seems to be something off with my syntax. It validates fine but nothing happens… Anything catch your eye? Thanks in advance for any help.
- id: movieTime
alias: 'Movie time'
trigger:
platform: state
entity_id: media_player.kodi_kodipilocal
action:
- service_template: >
{% if (states.media_player.kodi_kodipilocal.attributes.media_content_type) == 'movie' %}
light.turn_off
{% elif (trigger.to_state.state) == 'idle' %}
light.turn_on
{% endif %}
entity_id: light.livingroom_ceiling
data:
brightness_pct: 50