Binary sensor value template with multiple motion sensors

Allright, I hope someone can help me out. I thought this would be easy, but it isn’t :sweat_smile:

I have a couple of motion sensors throughout the house and I wan’t to be able to “record” motion. For example

  • if motion sensor just outside the bedroom goes from off to on
  • and within 30 seconds the motion sensor on the lower stairs also goes from off to on
  • set “someone_goes_down” to true

Bases on this, I can create some automations, like turn on the sonos, turn on the lights and turn on the coffee machine

I thought it would be easy to just maken an automation with these two steps, but I can’t figure out where to place the status

If I have this code:

someone_going_down:
        friendly_name: Someone going down?
        device_class: motion

It states I miss a value template, but I don’t know what to put there?

Kick. Someone?

You’d have to make an automation to handle this logic. I’d suggest you start looking into it from that perspective.

But within an automation there is also aproblem;

I can add a trigger that looks if sensor 1 changes from off to on. But When I add the second trigger, there is no “within X period” option. so

  • Sensor 1 goes from off to on &
  • Sensor 2 goes from off to on

But this never happens at the same time, there has to be a “group” that states it may happen within 20 or 30 seconds.

Also; once that’s done, there is no sensor to change from “not going up” to “going up” (or down).

You may wish to review the following post which addresses a similar requirement:

When motion is detected outside a room it proceeds to wait for motion in another location (for up to 2 minutes). Depending on whether this additional motion was detected, a switch is turned on (or not).

In your case, it could set an input_boolean’s state (or not).

Nice. The “idea” of the function works, but not yet perfect. What I’ve got right now is quite what you’ve mentioned

Trigger one is the sensor (1)
then there is a time-out from 30 seconds for the second sensor.

When both sensors are “on”, the input boolean goes to on. ← all fine

The downside is, that the automation waits for the timeout to be completed. So if I was walking down for example, the lights would only go on afther 30 seconds, when the timeout is compelted. But I want to fire that as soon as the second sensor goes on.

Is that possible?

That’s not how a wait_for_trigger works.

The wait_for_trigger triggers as soon as the desired event occurs. It will wait a maximum of the timeout value for the event to occur.

Script - wait_for_trigger - timeout

I’ve seen that, but I’m not enough of a programmer to work with the “wait.completed” or anything like that elements…

So are you giving up or do you want my help to implement it?

Your help (or anyones help) would be much appreciated. What I’ve got so far is this, pure based on UI automation.

- id: '1650002654833'
  alias: Sensors - Someone is going up
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.shelly_overloop_motion
    from: 'off'
    to: 'on'
  condition: []
  action:
  - wait_for_trigger:
    - platform: state
      entity_id: binary_sensor.shelly_zolder_motion
      from: 'off'
      to: 'on'
    timeout: 00:00:30
    continue_on_timeout: true
  - service: input_boolean.turn_on
    data: {}
    target:
      entity_id: input_boolean.someone_going_up
  mode: single

I’m pretty new to HA but this is the simplest way i could think of via UI only.

Create new helper via Configuration > Helpers > Timer (Duration 30 seconds)

Create automation to start the timer

Name: Start bedroom timer

Triggers

Trigger Type: State
Entity: Bedroom Motion Sensor
From: off
To: on

Actions

Action type: Call service
Service: Timer: Start
Target: Bedroom Timer

After 30 seconds the state will change from active to idle

Create a second automation

Name: Lower stairs motion

Trigger Type: State
Entity: Lower Stairs Motion Sensor
From: off
To: on

Conditions

Condition type: State
Entity: Bedroom Timer
State: active

Make sure the timer is running

Actions

Here you can set someone_goes_down to true, turn on lights, stop the timer or whatever, hope it helps. This can be done differently or via just one automation by using trigger ids, just wanted to keep it simple.

@RickTSD
Your automation looks good, but you have to set continue_on_timeout: to false.
With set to true it would always turn the boolean on even the when the zolder_motion sensor remains off.

  • If wait_for_trigger is triggered within its timeout duration (30 seconds), the variable wait.trigger will have a value.

  • If wait_for_trigger is not triggered within its timeout duration (30 seconds), the value of wait.trigger will be none.

We can use this information to determine if input_boolean.someone_going_up should be set to on (motion was detected by binary_sensor.shelly_zolder_motion within 30 seconds) or to off (motion was not detected by binary_sensor.shelly_zolder_motion within 30 seconds).

- id: '1650002654833'
  alias: Sensors - Someone is going up
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.shelly_overloop_motion
    from: 'off'
    to: 'on'
  condition: []
  action:
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.shelly_zolder_motion
        from: 'off'
        to: 'on'
    timeout: '00:00:30'
  - service: "input_boolean.turn_{{ 'off' if wait.trigger == none else 'on' }}"
    target:
      entity_id: input_boolean.someone_going_up
  mode: single

Thanks man!! This did the trick!!

@lookman I must say I like the thoughts of this automation. It is that 123 had a solution I’ve tried first, but thanks!!

1 Like