Automation: room entry and exit lights

I’m brand new to home assistant. I just switched from smartthings and am really excited about the possibilities. I’m trying to recreate an automation I had on my smartthings system and could really use some help

Here’s my setup. I have 2 motion sensors, one on the inside of a room, and one on the outside. I’ve restricted the beams to capture only exit and entry. I have a z wave light switch in that room as well.

My general setup in sudo code would be this:

trigger:
 outside motion sensor activated
condition:
  inside motion sensor was activated in the last 5 seconds
action:
  turn light off

I think I’ve got everything figured out except for the condition. Any help would be much appreciated.

Did you check the cookbook?

And if you ask me, I’d only use the inside motion sensor.

I did see that but I don’t think that would quite work. The purpose of using both sensors in to ensure there aren’t false positives.

Which is why I’d go with the one sensor option :wink:

Anyway, I don’t know your local situation so please go for whatever works best for you :slight_smile:

your condition should be something like

{{ (as_timestamp(now())-as_timestamp(states.sensor.sn1_reed.last_updated)) < 5 }}

This might help.

Here is what I ended up doing.

- alias: redacted
  hide_entity: True   
  trigger:
    - platform: state
      to: 'on'
      entity_id: binary_sensor.ecolink_motion_detector_sensor_2  
  condition:
    - condition: template
      value_template: '{{as_timestamp(now()) - as_timestamp(states.binary_sensor.ecolink_motion_detector_sensor.last_changed) < 5}}' 
  action:
    service: homeassistant.turn_off
    entity_id: light.ge_12724_3way_dimmer_switch_level

 - alias: redacted
      hide_entity: true  
      trigger:
        - platform: state
          to: 'on'
          entity_id: binary_sensor.ecolink_motion_detector_sensor  
      condition:
        condition: and
        conditions:
        - condition: sun
          after: sunset
          after_offset: "-1:00:00"
        - condition: template
          value_template: '{{as_timestamp(now()) - as_timestamp(states.binary_sensor.ecolink_motion_detector_sensor_2.last_changed) < 5}}'
      action:
        service: homeassistant.turn_on
        entity_id: light.ge_12724_3way_dimmer_switch_level

Thanks for the help I really do appreciate it!

1 Like