Juggler
(SR)
May 30, 2018, 6:30pm
1
I have a Insteon 6-button switch and a Z-wave plug-in module attached to a light. Both are working. I would like to setup an automation such that if I toggle one of the buttons, the light toggles accordingly (i.e. turn switch on, light turns on…)
I’ve tried the following automation, but it is not working. Is a service_template the best way to accomplish the toggle? Can anyone help me debug this?
- id: '1527696983201'
alias: toggle coffee table light
trigger:
- entity_id: switch.livingroom_keypadlinc_4
platform: state
action:
service_template: >
light.{% if is_state('switch.livingroom_keypadlinc_4', 'on') %}
turn_on
{% else %}
turn_off
{% endif %}
data:
entity_id: light.leviton_unknown_type1706_id0334_level
ih8gates
(Scott Reston)
May 30, 2018, 6:36pm
2
Spaces will be rendered by your service template. Just a quick guess, but removing them may do the trick. You do that with a - (minus).
service_template: >-
light.{% if is_state('switch.livingroom_keypadlinc_4', 'on') %-}
turn_on
{-% else %-}
turn_off
{-% endif %}
Also - make sure you run your templates through the template dev tool to confirm that you don’t have errors.
petro
(Petro)
May 30, 2018, 6:42pm
3
You can’t piece together your string the way you are trying to do it. Logic has to be separate lines.
- id: '1527696983201'
alias: toggle coffee table light
trigger:
- entity_id: switch.livingroom_keypadlinc_4
platform: state
action:
service_template: >
{% if is_state('switch.livingroom_keypadlinc_4', 'on') %}
light.turn_off
{% else %}
light.turn_on
{% endif %}
entity_id: light.leviton_unknown_type1706_id0334_level
Or you could use the toggle service.
- id: '1527696983201'
alias: toggle coffee table light
trigger:
- entity_id: switch.livingroom_keypadlinc_4
platform: state
action:
service: light.toggle
entity_id: light.leviton_unknown_type1706_id0334_level
4 Likes
Juggler
(SR)
May 31, 2018, 2:00am
4
Thanks… Going with the service_template rather than toggle. This will ensure if anything does get out of sync, they’ll be brought back inline.
Thank you for this code. It worked great for me to setup a toggle from a wink relay button