Hi
Sorry but struggling with the following:
I have an input_boolean (front_camera_motion) that is set ‘on’ whenever my external camera detects motion.
I’m trying to just turn on a light for 5 minutes, and then only turn it off if it wasn’t on in the first place.
Also after 5 minutes i will reset the camera motion flag to off to start the cycle again.
My code looks like:
alias: do_front_camera_processing
initial_state: True
hide_entity: False
trigger:
platform: state
entity_id: input_boolean.front_camera_motion
from: ‘off’
to: ‘on’
action:
#-- motion detected!!! #-- capture master bedroom light current state. is it on or off? store into input_number.front_light_state #-- Not sure this is the correct command. Trying to store the current state of the master bedroom light.
service: input_number.set_value
data:
entity_id: input_number.front_light_state
value:{{ (states.light.master_bedroom) | int }}
#-- turn light on regardless… i.e. if it was already on then no change
alias: front lights off
trigger:
platform: state
entity_id: input_boolean.front_camera_motion
to: ‘on’
for:
minutes: 5
action:
condition:
#-- first reset the camera motion detection flag
service: input_boolean.turn_off
entity_id: input_boolean.front_camera_motion
#-- next this is the section i’m struggling with. so if input_number.front_light_state = 0 then light was originally off?? and now want to turn it off (within this same action section), but how to code? #-- if condition light was originally off then turn light off
Please can you help with the above or suggest an alternative approach?
Can you edit your post and use the </> button around your code sections. The way you posted it removes all the correct white space. Also, maybe you can use my automation for motion detecting light as a guide:
automation section:
- alias: Hall Motion Detected During Night
trigger:
- platform: state
entity_id: binary_sensor.hallway_ms_sensor_32_0
to: 'on'
condition:
- condition: time
after: '23:00:00'
before: '07:00:00'
action:
- service: homeassistant.turn_on
entity_id: script.hall_motion_night
- alias: Hall Motion Detected During Day
trigger:
- platform: state
entity_id: binary_sensor.hallway_ms_sensor_32_0
to: 'on'
condition:
- condition: time
after: '07:00:00'
before: '23:00:00'
action:
- service: homeassistant.turn_on
entity_id: script.hall_motion_day