Hi!
Is there an option to pass value of sensor directly to the switch
entity state?
Like
action:
do_magic:
entity_id: switch.my_cool_socket
value: {{ states('sensor.my_cool_calculated_sensor') }}
instead of writing long story with choose
or if-then-else.
I want to use template sensor which has on/off values to control my power socket.
Thank you.
Troon
(Troon)
May 5, 2022, 9:42am
2
What are the actual values of your sensor? If it’s on/off, it should probably be a binary sensor. Assuming it contains the strings “on” or “off”, this should work:
action:
- service: "switch.turn_{{ states('sensor.my_cool_calculated_sensor') }}"
entity_id: switch.my_cool_socket
Alternatively: Template Switch - Home Assistant
Looks like interpolation doesn’t work there, it says
Message malformed: value must be one of ['toggle', 'turn_off', 'turn_on'] for dictionary value @ data['type']
Here’s what I did:
type: turn_{{ states('sensor.room_fumigator_set_status') }}
device_id: 972de552c017e05142073d03d99c9207
entity_id: switch.room_fumigator
domain: switch
{{ states('sensor.room_fumigator_set_status') }}
shows off
in template editor