Clocks go back and automation queue reaches 30000

I have an automation with a time pattern trigger which checks all the motion sensors in the house and sets an input_boolean to “on” if there is no movement anywhere. It’s supposed to run every 30 minutes.

Sounds simple, and all has been well for several weeks, but suddenly I get a massive queue:

Logger: homeassistant.components.automation.no_movement
Source: helpers/script.py:1344
Integration: Automation (documentation, issues)
First occurred: 01:38:35 (202605 occurrences)
Last logged: 01:59:59

No movement: Already running

Presumably something to do with Summer Time ending and the clocks going back? If so, how do I stop it happening next year? The automation is pretty simple:


- id: '1630684772441'
  alias: No movement
  description: Runs every 30 min. If no movement has been registered by any motion
    sensor for 30 min , set flag to on (flag turned off again when movement detected
    in any room).
  trigger:
  - platform: time_pattern
    minutes: /30
  condition:
  - condition: state
    entity_id: binary_sensor.bedroom_motion_sensor_motion
    state: 'off'
    for:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0
  - condition: state
    entity_id: binary_sensor.landing_motion_sensor_motion
    state: 'off'
    for:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0

# Condition repeated for each motion sensor... Left out here for brevity's sake.

  action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.no_movement
  mode: single

Sorry, I see someone else has posted exactly the same problem. Don’t seem to be able to delete mine for some reason…

As usual with time patter triggers, there’s a more efficient way for your automation. I still haven’t seen an automation where a time pattern trigger is needed and there’s no more efficient solution.

Create a group containing all your motion sensor, then trigger on this group going to off for 30 minutes.

- id: '1630684772441'
  alias: No movement
  description: Runs every 30 min. If no movement has been registered by any motion
    sensor for 30 min , set flag to on (flag turned off again when movement detected
    in any room).
  trigger:
  - platform: state
    entity_id: group.motion_sensor_group
    to: 'off'
    for:
      minutes: 30
  action:
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.no_movement
  mode: single

I assume you have another automation that turns the boolean back off, so there would even be a better solution by creating a binary_sensor.

binary_sensor:
  - platform: template
    sensors:
      no_movement:
        friendly_name: No movement for 30 minutes
        value_template: "{{ is_state('group.motion_sensor_group', 'off') }}"
        delay_on:
          minutes: 30

This sensor will be on if there’s no motion for 30 minutes and off if there’s any motion. No automationa needed.

2 Likes

Excellent! Thank you. :grinning:

However, be aware that the 30 minute timer will be affected by automation reloads or HA restarts during that time period.

And it doesn’t just start back up waiting for the next 30 minutes afterward either. One of the motion sensors will need to change states again before the 30 minute timer starts up again. So depending on how your automation is set up there could be no motion at all for several hours and the automation would never trigger.

the binary sensor would suffer from the same HA restart limitation as well.

I’m totally aware of that. For me that doesn’t matter, nowadays I barely reload automations and reatart only when updating HA. My system never restarted itself in the last 5 years.

Also his initial automation with the time pattern trigger suffers from the same issue anyway.

Sorry, it sounded like I was directing that toward you. not at all.

it was for the OP

I’m not actually sure that’s the case.

does the condition use the “last_changed” and the “on” state to set the condition true or does it check that the condition state has been “on” using another means like using the history in the same way the history graph does?

My tendency is that it does the former (because why would HA treat the condition any different IOW more reliably :roll_eyes:) so you would be right. But again I don’t know that for a fact.

It sure would be nice to have a more reliable timer function in HA so we no longer need to worry about stuff like this.

Ah, I understand I got a notification that you replied to me, so that’s why I thought it was directed toward me :slight_smile:

I would be extremly surprised if the conditions do that differently than the triggers, but I also can’t tell it for sure.

1 Like