I have an Ikea on/Off button and try to make a blueprint for it.
To keep it simple and get some practice I wrote some thing that switches on a light when de On button is pressed and turns the light off it the On button is pressed again.
I came up with this:
blueprint:
name: A Test
domain: automation
input:
remote:
name: Remote
description: The remote that will control the lights
selector:
device:
integration: zha
manufacturer: IKEA of Sweden
model: TRADFRI on/off switch
target_light:
name: Lights
description: The lights that will be controlled
selector:
target:
entity:
domain: light
mode: restart
variables:
target_light: !input target_light
command: "{{ trigger.event.data.command }}"
cluster_id: "{{ trigger.event.data.cluster_id }}"
endpoint_id: "{{ trigger.event.data.endpoint_id }}"
trigger:
- platform: event
event_type: zha_event
event_data:
device_id: !input remote
action:
- choose:
# On Pressed
- conditions:
- "{{ command == 'on' }}"
- "{{ cluster_id == 6 }}"
- "{{ endpoint_id == 1 }}"
- condition: state
# this troubles me
entity_id: !input target_light
state: "off"
sequence:
- service: light.turn_on
target: !input target_light
# On Pressed
- conditions:
- "{{ command == 'on' }}"
- "{{ cluster_id == 6 }}"
- "{{ endpoint_id == 1 }}"
- condition: state
# this troubles me
entity_id: !input target_light
state: "on"
sequence:
- service: light.turn_off
target: !input target_light
# Off Pressed
- conditions:
- "{{ command == 'off' }}"
- "{{ cluster_id == 6 }}"
- "{{ endpoint_id == 1 }}"
sequence:
- service: light.turn_off
target: !input target_light
It doesn’t work. I see the blue print in my blueprints list. I create an automation but it is not visible in the automations page.
But…
if I change
- condition: state
entity_id: !input target_light
state: "on"
to:
- condition: state
entity_id: light.hue_office_huelight
state: "on"
All is fine. So how can I use the target_light from the selection in the state condition?