Hey,
I presume Im making a very simple mistake, but the following automation (when I select the Nintendo Switch in the input selector):
- alias: cinema_room_scene_automation
trigger:
platform: state
entity_id: input_select.cinema_room_scenes
action:
service: remote.turn_on
data:
entity_id: remote.cinema_room
# activity: 'Cinema Room Switch'
data_template:
activity: >
{% if is_state("input_select.cinema_room_scenes", "Chromecast") %}
'Cinema Room Chromecast'
{%-elif is_state("input_select.cinema_room_scenes", "NintendoSwitch") %}
'Cinema Room Switch'
{%-elif is_state("input_select.cinema_room_scenes", "PS3") %}
'Cinema Room PS3'
{% else %}
'PowerOff'
{% endif %}
results in the following log error:
2020-04-26 11:52:52 ERROR (MainThread) [homeassistant.components.harmony.remote] Cinema Room: Activity 'Cinema Room Switch' is invalid
However, removing the data_template
and uncommenting the activity line under data
results in the Harmony activity starting without issue.
So what have I done wrong?
Its always moments after you submit that you find the answer - for reasons I don’t understand, you seem to have to remove the quotes,
so the following worked:
- alias: cinema_room_scene_automation
trigger:
platform: state
entity_id: input_select.cinema_room_scenes
action:
service: remote.turn_on
data:
entity_id: remote.cinema_room
# activity: 'Cinema Room Switch'
data_template:
activity: >
{% if is_state("input_select.cinema_room_scenes", "Chromecast") %}
Cinema Room Chromecast
{%-elif is_state("input_select.cinema_room_scenes", "NintendoSwitch") %}
Cinema Room Switch
{%-elif is_state("input_select.cinema_room_scenes", "PS3") %}
Cinema Room PS3
{% else %}
PowerOff
{% endif %}
For your information: No need to have data and data_template in the same action. You can reduce it to this:
action:
service: remote.turn_on
data_template:
entity_id: remote.cinema_room
activity: >
{% if is_state("input_select.cinema_room_scenes", "Chromecast") %}
Cinema Room Chromecast
{%-elif is_state("input_select.cinema_room_scenes", "NintendoSwitch") %}
Cinema Room Switch
{%-elif is_state("input_select.cinema_room_scenes", "PS3") %}
Cinema Room PS3
{% else %}
PowerOff
{% endif %}
1 Like
Thanks @Burningstone, I’ll revert that now.
I did start like that, but the change was one of many I tried to see what was breaking me.
tom_l
5
But also make sure you remove the quotes (as you found). They are not needed for multi-line templates.
1 Like
Good catch, I corrected my post accordingly.