Unable to delete automation accidentely created in conifguration.yaml without id

Hi,

I didnt use HA for a while and accidentely created then an automation in the configuration.yaml which looked like this:

automation:
  - alias: "Bewegungssensor im Büro erkannt"
    trigger:
      - platform: state
        entity_id: binary_sensor.sensor_buro
        to: "on"
    action:
      - service: light.turn_on
        entity_id: light.extended_color_light_1
      - service: switch.turn_on
        entity_id:
          - switch.dave_buro_steckdose_1
          - switch.daves_buro_steckdose_2
      - service: timer.start
        data:
          entity_id: timer.bewegung_timer

  - alias: "Timer für Bewegungssensor zurücksetzen"
    trigger:
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.bewegung_timer
    action:
      - service: timer.cancel
        entity_id: timer.bewegung_timer

  - alias: "Ausschalten der Lampen nach Ablauf des Timers, wenn keine Bewegung mehr erkannt wird"
    trigger:
      - platform: state
        entity_id: binary_sensor.sensor_buro
        to: "off"
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.bewegung_timer
    condition:
      - condition: state
        entity_id: binary_sensor.sensor_buro
        state: "off"
    action:
      - service: light.turn_off
        entity_id: light.extended_color_light_1
      - service: switch.turn_off
        entity_id:
          - switch.dave_buro_steckdose_1
          - switch.daves_buro_steckdose_2

after i realised that there is a way easier way in the automations tab in the gui itself (as i said, didnt use it for quite a while)

i deleted the code and rebooted…
Sadly they are still visible in the UI

and if i try to delete them in the UI, i get the an Erroro popup which says

Only automations in automations.yaml can be deleted

i tried to reproduce it, but as I didnt specifiy and “id”, i can’t do that, it will just create new ones. (at least i think so, and i don’t want to clog my Automations UI with dead automations)

if i try to edit the automation via gui on the cog wheel, it displays

This entity ('automation.ausschalten_der_lampen_nach_ablauf_des_timers_wenn_keine_bewegung_mehr_erkannt_wird') does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.

any idea how i can get rid of it?

If you have automations made in YAML in any other file than automations.yaml - then you can just delete the entire automation and reload automations or restart HA.

You should not have any left overs (though I have seen a lot of left overs of other things in HA). I just tried to add exactly your first automation to one of my included automation yaml files and removed it again by deleting it from the file and it is gone.

Are you sure you did not accidently pull it into your automations.yaml file via the UI? Search for these automations in automations.yaml. If they are there - delete them manually

Thanks a lot for your anser.

mhm very strange.

My automations.yaml ha currently just one automation in it (as intended) and looks like this:

- id: '1696336963923'
  alias: Dave Bürolicht
  description: Schaltet Licht ein und wieder aus wenn es 20min keine Bewegung erkannt
    hat
  use_blueprint:
    path: homeassistant/motion_light.yaml
    input:
      motion_entity: binary_sensor.dave_buro_sensor
      no_motion_wait: 1200
      light_target:
        device_id: 21029c848792730ac817c441f731f050

and my configuration.yaml looks like this

# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#Cloudflare Tunnels Setups für deleven.net, siehe https://www.youtube.com/watch?v=saqvt9aEQPs&t=394s
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

http:
  cors_allowed_origins:
    - https://google.com
    - https://www.home-assistant.io
  ip_ban_enabled: true
  login_attempts_threshold: 5
  use_x_forwarded_for: true
  trusted_proxies:
    - 172.30.33.0/24


#----------------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------------------------------------
#HOMEKIT (Super Guide ist hier https://www.youtube.com/watch?v=XCDhMYgHqco&t=319s)
#----------------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------------------------------------
#----------------------------------------------------------------------------------------------------------------------------------------------------

homekit:
  - name: HASS Bridge #So wird die Bridge heissten
    port: 21063
    filter:
      include_domains:
        - light
        - switch
        - sensor
        - scene
        - binary_sensor
#      include_entity_globs:
#        - climate.heizung_*_int*
#      include_entities:
#        - climate.1e89f334
#        - sensor.landroid_oben_l1000_error
#        - sensor.landroid_unten_error
#        - switch.brunnen_socket_1
#        - fan.levoit_core300s
#      exclude_entities:
#        - light.shapes_e22c
#    entity_config:
#      switch.office:
#        type: outlet

#  - name: HASS Bridge Lock #Diese Bridge ist speziell als accessory definiert (Für Kameras, Schlösser, TV-Mediaplayer, und Activity Bases Remote ) siehe hier warum https://www.home-assistant.io/integrations/homekit/#accessory-mode
#    port: 21064
#    mode: accessory
#    filter:
#      include_entities:
#        - lock.hausturoffner

I also checked the othe .yaml file (groups, scenes, scripts, secrets) and there is no automation in it

wondering what happend here

Well. I have seen many times that Home Assistant is very fragile when it comes to all the places it stores data.

There is a place you can look BUT… Make a backup first. Then backup the file. I cannot repeat this enough. Backup first!

In the config directory called .storage (hidden) you find a file called core.entity_registry

It is a json formatted file so a human can edit it. I hope noone ever gets the idea of putting this in an optimized database because I have had to hack this file more often that I should have had to

One comma too many or too few and home assistant crashes. Backup. If possible stop HA while you do this

Fine the entity name of your ghost automation. You should be able to see that. If nowhere else then in the listing in developer tools → states.

Then open the core.entity_registry file and search for it.

An automation entry in this file looks like this

      {
        "aliases": [],
        "area_id": null,
        "capabilities": {
          "id": "Start indoor motion sensor timer"
        },
        "config_entry_id": null,
        "device_class": null,
        "device_id": null,
        "disabled_by": null,
        "entity_category": null,
        "entity_id": "automation.start_indoor_motion_sensor_timer",
        "hidden_by": null,
        "icon": null,
        "id": "0933ae1271cf8652ca807b37f9a03cfb",
        "has_entity_name": false,
        "name": null,
        "options": {
          "conversation": {
            "should_expose": false
          },
          "cloud.alexa": {
            "should_expose": false
          },
          "cloud.google_assistant": {
            "should_expose": false
          }
        },
        "original_device_class": null,
        "original_icon": null,
        "original_name": "Start indoor motion sensor timer",
        "platform": "automation",
        "supported_features": 0,
        "translation_key": null,
        "unique_id": "Start indoor motion sensor timer",
        "unit_of_measurement": null
      },

You need to delete the entire thing.

Note the comma after the }
Ie. },

After your edit you will want ONE comma, not two and not zero.

Except - if it is the last record in the list and you remove this last record, then the new last record must have no comma after it. These commas is what gets people when they edit these files. There is no forgiveness. That is why everyone says you should not edit these files. But in some cases it is the only way to get rid of trash left because HA is still buggy. Or was buggy when you did something.

Then start HA again and check that the problem is gone. If HA crashes then you goofed up the json. That is why you have that backup - right?

1 Like

Thank you very much, i will consider the advice when there will be a new problem.
This one just sorted itself out.

Instead of restarting HA, I just rebooted the whole VM (could have done that in the begining…) and suddenly they are gone.
But I’m sure the core.entity_registry will prove useful for me at some point.

Thanks again very much