Excessive memory usage when two automations enabled

Hi,

I have two automations that manage the lights around my front door.

  • The first turns the porch light on for two minutes when one of two sensors is triggered.
  • The second turns on the inside light for two minutes, if a contact sensor on the door is triggered after the motion sensor outside is triggered.

The motion sensor outside is the only thing the two automations have in common.

When both rules are enabled and triggered, the memory usage within Home Assistant increases to 100% over about 30 minutes and my VM stops responding.

Disabling either automation stops this happening.

It’s almost like each automation is causing the other to loop, or something, but as mentioned, the only thing the two automations have in common are the sensors that trigger them,

The two automations are below. Does anyone have any theories about what might be going on?

Home Assistant is running on in a x64 vm using the supervised install.
HA version is 2024.4.3.

alias: Light - Front Door
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.front_door_sensor_state
      - binary_sensor.front_door_contact_sensor
    not_from:
      - unknown
      - unavailable
    to: "on"
condition:
  - condition: or
    conditions:
      - condition: sun
        before: sunrise
      - condition: sun
        after: sunset
action:
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.porch_light
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - repeat:
      sequence:
        - service: light.turn_off
          data: {}
          target:
            entity_id: light.porch_light
      until:
        - condition: and
          conditions:
            - condition: state
              entity_id: binary_sensor.front_door_sensor_state
              state: "off"
              for:
                hours: 0
                minutes: 2
                seconds: 0
            - condition: state
              entity_id: binary_sensor.front_door_contact_sensor
              state: "off"
              for:
                hours: 0
                minutes: 2
                seconds: 0
mode: restart
alias: Light - Entry Way
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.front_door_contact_sensor
    not_from:
      - unknown
      - unavailable
    to: "on"
    id: door
  - platform: state
    entity_id:
      - binary_sensor.garage_sensor_state
    to: "on"
    id: garage
condition:
  - condition: or
    conditions:
      - condition: sun
        before: sunrise
      - condition: sun
        after: sunset
action:
  - condition: or
    conditions:
      - condition: and
        conditions:
          - condition: trigger
            id:
              - door
          - condition: state
            entity_id: binary_sensor.front_door_sensor_state
            state: "on"
      - condition: and
        conditions:
          - condition: trigger
            id:
              - garage
          - condition: state
            entity_id: light.inside_lights
            state: "off"
  - service: light.turn_on
    data: {}
    target:
      entity_id: light.entry_way_light
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - if:
      - condition: or
        conditions:
          - condition: state
            entity_id: binary_sensor.front_door_contact_sensor
            state: "on"
          - condition: state
            entity_id: binary_sensor.garage_sensor_state
            state: "on"
    then:
      - service: automation.trigger
        data:
          skip_condition: true
        target:
          entity_id: automation.light_entry_way
    else:
      - service: light.turn_off
        data: {}
        target:
          entity_id: light.entry_way_light
mode: restart

Put a delay in your repeat loop. That will absolutely spam the crap out of the light turn off service without it. It executes extreemly fast.

Actually, at first I thought you were using it because the communication to your light is bad. But now I realise it is just a really bad way to do things. There is no call for a loop in an automation like this. It should be state driven.

Have a look at this example:

Also it is bad practice to trigger automations manually from other automations. If you need to re-use a set of actions often then write a script and call that from each automation instead.

Yes, I think you are right by them looping each other.

  • What happens if you change the mode to single?

  • Where I have multiple “switches” eg wall switch, presence, Time of day

I have been creating a new trigger for each and putting them in one automation using a choose: action from each trigger,

Then I use the Parallel mode for the smallest number of concurrent runs that will allow all triggers to work at once, EG 3 times if I have 1 wall switch, 1door and 1motion switch.

This gets even further complex still because I also run the timer from a helper so the automation can exit without running for any longer then needed.

Thanks. Now that you point it out it’s rather obvious that the turn off service would be spamming the switch.

Will fix.
Thanks