Hello everyone, I’m starting at home assistant, and I need a help with a script template sintax code.
I want that after the same command, according to which alexa he was given, a remote control of the living room or my room is used for a same script, for example, to return the TV channel (from the bedroom or living room) I created a script to choice between two IR.
Here is my sensors template:
- platform: template
sensors:
last_alexa:
value_template: >
{{ expand(states.group.all_echos) | selectattr('attributes.last_called','eq',True) | map(attribute='entity_id') | first }}
- platform: template
sensors:
ir_to_use:
value_template: >
{% if is_state("sensor.last_alexa", "media_player.echo_our_bedroom") %}
tasm_cont_rem_our_bedroom_6b90ff
{% else %}
tasm_cont_rem_living_room_5e1299
{% endif %}
and here is my problem with a sintax template, this script code wont work:
scr_tv_previous_chanel:
alias: scr_ TV previous chanel
sequence:
- service: mqtt.publish
data:
topic: cmnd/{{ sensor.ir_to_use }}/IRsend
payload: '{"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E008F7","Repeat":0}'
I also tested with data_template, and also
- service: mqtt.publish
data_template:
topic: cmnd/"{{ sensor.ir_to_use }}"/IRsend
payload: '{"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E008F7","Repeat":0}'
I made a code below that works, but I would like to use it as above:
- service: mqtt.publish
data:
topic: >
{% if is_state("sensor.last_alexa", "media_player.echo_our_bedroom”") %}
cmnd/tasm_cont_rem_our_bedroom_6b90ff/IRsend
{% else %}
cmnd/tasm_cont_rem_living_room_5e1299/IRsend
{% endif %}
payload: '{"Protocol":"SAMSUNG","Bits":32,"Data":"0xE0E008F7","Repeat":0}'