How to listen events of all motion and door sensors?


I’m trying to do an automation / blueprint that controls the occupancy status of the house. For this, I want to listen to all the events related to the motion or door sensors so that once the door of the house is closed, I can know if there is someone at home.

I have this code but it is not working well for me, it never enters. And i dont know how to fix it.

  - platform: event
    event_type: less_push_buttons
      target_entity_id: !input "area_state"
  - platform: event
    event_type: state_changed
  - condition: template
    value_template: "{{ trigger.event.event_type == 'less_push_buttons' 
      or (trigger.event.event_type == 'state_changed' 
          and (trigger.to_state.attributes.device_class == 'occupancy' 
              or trigger.to_state.attributes.device_class == 'motion'
              or trigger.to_state.attributes.device_class == 'opening')) }}"


Create a group containing all your security-related binary_sensors. Use the group’s state to trigger your automation.

The group’s state is ideal for monitoring whole-home occupancy:

  • When any member of the group changes to on the group’s state will be on.
  • When all members of the group are off the group’s state will be off.
1 Like


Thanks, I had already thought about that solution, the problem is that there are sensors like Aqara’s that are up to two minutes indicating movement, and it wouldn’t help me. What I need is to know when any sensor has changed from state to on, to indicate that there has been movement.

Your first post suggests you are interested in detecting occupancy.

Your latest post suggest you’re interested in movement.

Are you trying to detect occupancy or movement? There’s a subtle but important distinction between the two.

Yes, the Philips sensor only has occupancy, this is why i has used occupancy, but i want movement

I would simply use a State Trigger and list all security-related binary_sensors with a to: 'on' option. It is efficient because it triggers only when a desired entity changes state to on.

In contrast, this Event Trigger will trigger when any entity in your system changes state:

  - platform: event
    event_type: state_changed

Yes, it can help

You can create a helper input boolean and an automation that toggles this boolean whenever any of the motion sensors triggers. Then use this boolean as a trigger.

What kind of trigger would do that other than the State Trigger I have proposed?