[SOLVED]: How to create a sensor that activates when no motion sensor has been activated in the last hour

Dear all,

I have 3 xiaomi motion sensors with a group:

sensores_movimiento:
name: Sensores Movimiento
entities:
- binary_sensor.motion_sensor
- binary_sensor.presence_20
- binary_sensor.presence_21

I want to create a sensor that activates when no motion sensor has been activated in the last hour.

How I can create this sensor?, with a template?, and how I can define this templae?.

Thanks in advance,

binary_sensor:
  - platform: template
    sensors:
      no_movement_for_1hr:
        friendly_name: "No Movement for One Hour"
        device_class: movement
        value_template: >-
          {{ ( as_timestamp( now() ) - as_timestamp( states.group.sensores_movimiento.last_changed ) ) > 3600  }}

Or

binary_sensor:
  - platform: template
    sensors:
      no_movement_for_1hr:
        friendly_name: "No Movement for One Hour"
        device_class: motion
        delay_on:
          minutes: 60
        value_template: >
          {{ is_state('group.sensores.movimiento', 'off') }}

I find this easier to understand.
And movement is not a valid device class as far as I can see here.

3 Likes

Yeah that should have been motion, that’s what I get for not looking it up and going from memory.

1 Like

Dear tom_l and Burningstone,

First at all thanks for your help. Any of both sollutions worked. I configured for 5 minutes (to not wait 1 houre to check) and and it has not worked. I forced the group motion sensors and wait for 6 minutes:

image

But the binary sensor “No movement for 1 houre” (really 5 minuts) continues with Not detected state:

image

image

It seems taht your sintax is correct, but dont works…

Jose

Drop the device class, that’s not going to work for your sensor (on = movement, when actually you want on = no movement).

Though there is something else wrong as well.

Dont works also, I configured the sensor in the binary_sensors.yaml:

- platform: template
  sensors:
    no_movement_for_1hr:
      friendly_name: "No Movement for One Hour"
      #device_class: motion
      delay_on:
        minutes: 1
      value_template: >
        {{ is_state('group.sensores.movimiento', 'off') }}

The sensor shows all the time closed estate…

Jose

group.sensores.movimiento

Should be

group.sensores_movimiento

And please properly format your code,asdescribe in point 11 in the community guidelines.

Dear Burningstone, thanks a lot. Now is working well.

Thanks for your help to both.

Jose