Random strange behaviour with automations

Dear All

I have a strange behaviour with a few automations (all similar to the one below).

The flow is:

  1. if there is movement and if there is not enough light then
  2. save the current status in a temporary scene
  3. switch the light on (different color/brightness according to time)
  4. wait until there no movement
  5. restore the previous status (temp scene)

They usually work very well but from time to time (let’s say once a month, apparently randomly) the lights are not turned off.

Any idea what I am doing wrong?

Thank you
Stefano

EDIT: no restarts and no config changes happened during these malfunctioning

- id: corridoio_accendi_luce_se_movimento
  alias: Corridoio Accendi luce se movimento
  trigger:
  - platform: state
    entity_id: binary_sensor.sensore_corridoio_motion
    to: 'on'
  condition:
    condition: or
    conditions:
    - condition: numeric_state
      entity_id: sensor.sensore_corridoio_light_level
      below: 15.01
    - condition: numeric_state
      entity_id: sensor.sensore_giardino_light_level
      below: '500'
  action:
  - data:
      scene_id: corridoio_before
      snapshot_entities: light.luce_corridoio
    service: scene.create
  - choose:
    - conditions:
      - condition: or
        conditions:
        - condition: time
          after: '20:59:59'
          before: 00:00:00
        - condition: time
          before: 08:00:01
          after: 00:00:00
      sequence:
      - service: light.turn_on
        data_template:
          brightness: 48
          rgb_color:
          - 255
          - 0
          - 0
          entity_id:
          - light.luce_corridoio
    - conditions:
      - condition: and
        conditions:
        - condition: time
          after: 08:00:00
          before: '21:00:00'
      sequence:
      - service: light.turn_on
        data_template:
          color_temp: 333
          brightness: 194
          entity_id:
          - light.luce_corridoio
  - wait_for_trigger:
    - platform: state
      entity_id:
      - binary_sensor.sensore_corridoio_motion
      to: 'off'
      for:
        hours: 0
        minutes: 1
        seconds: 0
  - data: {}
    entity_id: scene.corridoio_before
    service: scene.turn_on
  mode: single

I have the same issue, sometimes it’s like it only restores half the previous state as well.

Very annoying!!

Possible explanation:

If Home Assistant is restarted, all automations are restarted.

That means that if any automation is in progress, such as waiting for a delay to expire or a wait_for_trigger to trigger, it’s cancelled and the balance of the automation’s actions are never executed. For example, scene.corridoio_before is never turned on.

In addition, any snapshot scenes that were created before the restart are gone after startup.

That would be good except it’s not during restarts. It can happen at any random point in the day. My automations react to Zabbix alerts so I can get quite a few in the day and sometimes random lights will remain red/green and others will revert to the previous state.

My reply was to the topic’s author, who explained it happens “once a month, apparently randomly”. They’ll have to determine if their system did/didn’t restart at the time of the incident.

In your case, I don’t know what might be causing the problem.

Sorry. I didn’t mean to hijack a thread with a similar issue. I consider myself told off!

I merely clarified that my post wasn’t meant to offer a potential explanation for everyone’s problems, just for the first post.

I just noticed that ste.luci amended the first post to include:

no restarts and no config changes happened during these malfunctioning

In that case, the cause of ste.luci’s problem may be a random and temporary communication failure where the transmitted command is not received by the device. Determining if that’s the actual cause can be challenging (owing to its random nature).

Hello

There were no restart, no power shortage not any strange network utilization.

Sometimes it happens at night, others on the evening (of course the automation isn’t triggered if there is light)

Could you please share your setup for this? I am trying to get Zabbix to alert HA and failing!

Maybe (maybe!!!) I found the reason.
Some lights occasionally become unavailable (no idea why).
It seems like when this happens during the automation timeout, the lights are not switched off.

I temporarily solved the issue with another automation:

if the light state changes from unavailable to anything else
and the corresponding sensor is clear
then switch the light off

I get HA to monitor a mailbox - here’s the template I use to do what I do :

  - sensor:
    - name: zabbix_alerts
      state: >-
              {% if 'PROBLEM:' in trigger.event.data["subject"] and '<redacted>' not in trigger.event.data["subject"] %}
                   problem
              {% elif '<redacted>' in trigger.event.data["subject"] and 'PROBLEM' in trigger.event.data["subject"] %}
                   <redacted>
              {% elif 'OK:' in trigger.event.data["subject"] %}
                   no_problem
              {% endif %}
      attributes: 
        subject: "{{ trigger.event.data['subject'] }}"
        
    trigger:
    - event_data:
        sender: [email protected]
      event_type: imap_content
      id: custom_event
      platform: event 

Then I simply trigger my automations on “problem” or “no_problem” :slight_smile:

1 Like