Hi. N00b here. Trying to do this via the Automation GUI but something is not right. When motion is cleared, it doesn’t trigger, only when motion is active. Thoughts? and Thanks in advance.
alias: Auto - See Kitchen in Dark
description:
trigger:
- platform: state
entity_id:
- binary_sensor.ms_somewhere_motion_detection
condition:
- condition: time
before: "15:00:00"
after: "09:00:00"
action:
- if:
- condition: state
entity_id: binary_sensor.ms_somewhere_motion_detection
state: "on"
then:
- service: light.turn_on
data:
brightness_pct: 20
target:
entity_id: light.under_cabinet_light
else:
- if:
- condition: state
entity_id: binary_sensor.ms_somewhere_motion_detection
state: "off"
- condition: and
conditions:
- condition: state
entity_id: binary_sensor.ms_somewhere_motion_detection
state: "off"
for:
hours: 0
minutes: 0
seconds: 59
then:
- service: light.turn_off
data: {}
target:
entity_id: light.under_cabinet_light
mode: single
It will only fire when motion is detected in the trigger. You could also add when motion is cleared in the trigger and handle that in your action-if section.
While you are in the Automation Editor, click the overflow icon in the upper right corner (three vertical dots) and switch the Editor from Visual to YAML mode.
Copy the example posted above and paste it into the Editor (overwrite whatever YAML may already be there)
Click the Save button.
Optionally switch the Editor back into Visual mode to see how the automation is presented.
So I noticed the two triggers are defined, but only 1 action is defined to turn on lights when “on” has occurred on the motion detector. How does the light turn off? I would assume an action for “off” must be defined.
Trying to understand the logic ofit all. I could be missing something. Appreciate the help.
Most lights turn off when their brightness is set to zero. If your light doesn’t then the automation will need an explicit light.turn_off service call.