If Else automation for motion and turn on switch/light

An if-then-else isn’t mandatory for this application.

alias: Auto - See Kitchen in Dark
description:
trigger:
 - platform: state
   entity_id: binary_sensor.ms_somewhere_motion_detection
   from: 'off'
   to: 'on'
 - platform: state
   entity_id: binary_sensor.ms_somewhere_motion_detection
   from: 'on'
   to: 'off'
   for:
     seconds: 59
condition:
 - condition: time
   before: "15:00:00"
   after: "09:00:00"
action:
 - service: light.turn_on
   data:
     brightness_pct: "{{ 20 if trigger.to_state.state == 'on' else 0 }}"
   target:
     entity_id: light.under_cabinet_light
mode: single
1 Like