Automation/Script Intermittently fails

I have the below automation and two scripts below. The majority of the time it works perfectly, as expected. However, from time to time, it either fails to work at all or partly works (some entities trigger but others don’t).

The strange thing is, if I go to my automation yaml, and delete then reinsert one character at random, then save and restart, the automation works successfully again.

What could cause that? Is there an issue with coding? It’s unusual behaviour, especially if I don’t have to even save in between changing the character in the yaml file.


- alias: Weekday Wake
    platform: state
    entity_id: binary_sensor.staircase_sensor_motion
    to: 'on'
    condition: and
    - condition: time
      - mon
      - tue
      - wed
      - thu
      - fri
    - condition: time
      after: '06:00:00'
      before: '07:30:00'
    - condition: template
      value_template: "{{ (is_state('sensor.m_iphone_battery_state', 'Not Charging') or is_state ('sensor.r_iphone_battery_state', 'Not Charging')) and is_state ('media_player.sky_q','off') }}"
  - service: script.weekday_wake
  - service: script.morning_living_room

Script - Weekday Wake

  alias: Weekday Wake
  - service: media_player.turn_on
      entity_id: media_player.sky_q
  - delay: 2
  - service: media_player.select_source
      entity_id: media_player.sky_q
      source: ITV HD

Script Morning Living Room

  alias: Living Room Morning
  - service: light.turn_on
      entity_id: light.cabinet
      brightness: 140
      - 255
      - 160
      - 39
      transition: 10
  - service: light.turn_on
      entity_id: light.tv_unit
      brightness: 60
      - 203
      - 110
      - 93
      transition: 10
  - service: light.turn_off
    entity_id: light.lounge_light

Thanks Tom. I tried the first steps of the troubleshooting but it appears I have duplicates of every automation, for some reason. All my automations were created directly in the yaml file and that file only shows one instance of each automation.

However, in the automation configuration every one is listed twice. In each case one instance is turned on, the other turned off. When I hover over the clock, I get the message ‘Only automations that have a unique ID assigned are debuggable’.

I have no idea where the duplicate automations have come from. Example below.

Add an id: to your automation that is unique to all automations in order to debug. This is explained in the link tom provided.

- alias: Weekday Wake
  id: weekday_wake

Thanks for both replies. But can anyone explain why HA would create duplicates for every automation as I definitely haven’t done that, and I’ve been careful to only create each one within yaml.

how about add the unique_id first and then verify the duplicates exist after. If they still exist, make sure they aren’t deletable. If they are deletable, that means the system got confused at some point due to a lack of unique_id’s. Just delete the duplicates at that point through the entity list.

I’ve added the unique id’s and the duplicates were still showing. Each one was deletable so I’ve deleted them and I’ll have to see if they reappear.

Thanks for your help.

They shouldn’t re-appear unless you change the unique_id.

Think of the unique_id as a “name” for a registry. If you register your name, the system knows you by that name. Then if you change your name, the system still knows your old name but not your new one. So it just creates a new registry. At that point, it looks like a duplicate, however nothing is attached to the old name because it’s now attached to the new name.

1 Like

Not sure where you deleted them but now check the Configuration / Devices / Entities page too. “Restored” (poor name) automations need to be deleted from there too.

1 Like

Thanks Tom. I’ve checked and there are no duplicate or restored automations.