zakharm
(Ryan)
1
I have a light that I want to turn on when motion is sensed, but I only want to issue the ‘on’ command if the light is ‘off’.
If the light is ‘on’ and it is at 50%, sending the ‘on’ command brings it to full brightness and that is undesirable.
Here is my automation with my condition. Thanks!
automation:
alias: Motion turn on lamp
trigger:
- platform: state
entity_id: binary_sensor.aeotec_multisensor_6_sensor_2
from: 'off'
to: 'on'
condition:
- platform: state
entity_id: binary_sensor.aeotec_multisensor_6_sensor_2
state: 'off'
action:
service: light.turn_on
entity_id: light.lamp
Try this:
automation:
alias: Motion turn on lamp
trigger:
- platform: state
entity_id: binary_sensor.aeotec_multisensor_6_sensor_2
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: light.lamp
state: 'off'
action:
service: light.turn_on
entity_id: light.lamp
Why the condition for the sensor? If it triggers to ‘on’, condition ‘off’ will not “fail”?
zakharm
(Ryan)
4
Good catch on the condition. I’ll try it with the lamp instead of the motion detector. I don’t know why I was trying it that way
zakharm
(Ryan)
5
@Danielhiversen solution worked for me. Thank you.
rpitera
(Robert Pitera)
6
@zakharm Can you post your corrected code? It will help other users searching later as well as me, following this thread now. Thanks!
kernald
(Marc Plano-Lesay)
7
The working code is in @Danielhiversen’s answer already
1 Like
zakharm
(Ryan)
8
I’m happy to post the solution and this would be a nice easy starter example for the documentation.
automation:
alias: Motion turn on lamp
trigger:
- platform: state
entity_id: binary_sensor.aeotec_multisensor_6_sensor_2
from: 'off'
to: 'on'
condition:
- condition: state
entity_id: light.lamp
state: 'off'
action:
service: light.turn_on
entity_id: light.lamp
4 Likes
rpitera
(Robert Pitera)
9
Thanks - steps like that can save later users tons of time.
1 Like
bmp
10
Thank you for this. It was just what I needed.
3 years later, but thanks to this I made my first automation, guys! awesome.
if doorbell rings, flash lights. of state was on, turn back on, if state was off, stay off.