I would like to link 2 lights.
If Light A is on, then wait 5 min and afterwards turn light B on.
If light A is off then turn light B off
The state of light B doesn’t provoke anything, so that I can light on or off without affecting the before stated logic.
I have set 2 triggers:
light A is on for 5 min
light A is off
Both triggers works as I would like them to work. Then on the Actions I have set:
“toggle light B”
It works Wonderfull until I play with ligth B then all goes to hell
How should I set the action so that light B state is set the same as light A ??
123
(Taras)
August 7, 2021, 12:52am
2
Post the automation(s) you have created.
I created the automation using the UI. I need to change somehow the action.
alias: Allumer vitrine salle de jeu
description: ''
trigger:
- platform: device
type: turned_on
device_id: 43e1a711644b4a6da6ffd8560285f5dc
entity_id: switch.kappa1_relay
domain: switch
for:
hours: 0
minutes: 5
seconds: 0
milliseconds: 0
- platform: device
type: turned_off
device_id: 43e1a711644b4a6da6ffd8560285f5dc
entity_id: switch.kappa1_relay
domain: switch
condition: []
action:
- type: toggle
device_id: a29100aca7c246ddb4a7bb29c257350b
entity_id: switch.tau_1_light
domain: switch
mode: single
You can try this-
alias: New Automation
description: ''
mode: single
trigger:
- platform: state
entity_id: switch.kappa1_relay
to: 'on'
for: '00:05:00'
- platform: state
entity_id: switch.kappa1_relay
to: 'off'
condition: []
action:
- service: >-
switch.turn_{{'on' if trigger.to_state.state == 'on' else 'off'}}
target:
entity_id: switch.tau_1_light
The action uses Automation State Trigger Variable .
1 Like
123
(Taras)
August 7, 2021, 1:19pm
5
The problem is that the action simply toggles the state of switch.tau_1_light
. That’s why when you change its state manually, it becomes out of synchronization with the state of switch.kappa1_relay
.
It works Wonderfull until I play with ligth B then all goes to hell
Ardysusilo’s example fixes that by explicitly setting the state of switch.tau_1_light
(to match the state of switch.kappa1_relay
) and not simply toggling it.
I’ll try Ardysusilo solution and report back
Update: It works. I used the UI interface for the automation so the final code was slightly different:
service: 'switch.turn_{{''on'' if trigger.to_state.state == ''on'' else ''off''}}'
entity_id: switch.tau_1_light