ErikE007
(Erik E007)
August 22, 2020, 7:51am
1
Hello, I am trying to create a script using an entity_id based on a variable passed to the script. In this example I can use 1 script for switching on 4 different sonoff switches
automation:
- alias: switch_sonoff_1
trigger: []
action:
- service: script.switch_sonoff_on
data:
switch: "1"
#script
switch_sonoff_on:
alias: "Switch sonoff 1-4 on"
sequence:
- service: switch.turn_on
entity_id: switch.sonoff_1000cadaec_<use variable switch>
So houw to create a template to add the switch number to the entity_id.
Olen
(Olen)
August 22, 2020, 9:00am
2
entity_id: “switch.sonoff_1000cadaec_{{ switch }}”
ErikE007
(Erik E007)
August 22, 2020, 12:13pm
3
Thanks Olen, and how to do when it is part of a message:
{{ states('sensor.date_time_stamp') }} status Sonoff {{ switch }}: {{ status.switch.sonoff_1000cadaec_<use variable switch>.state }}
Olen
(Olen)
August 22, 2020, 1:03pm
4
I’d do a multiline and something like
{% set entity = 'switch.sonof...' ~ switch %}
{{ states(entity) }}
(Sorry for the short answers. Mobile only here)
ErikE007
(Erik E007)
August 22, 2020, 1:24pm
5
No problem. It is working. Thanks…