Baffled by mqtt discovery and appDaemon

I keep seeing messages like this from one of my appDaemon apps:

Entity light.bedroom_hold_4 not found in AppDaemon

This is so confusing I’m not even sure I can characterize it.
I have a bunch of devices setup via MQTT, this being one of them, but there are several others. I have MQTT discover set to false in HA, and each of my devices is explicitly declared as a light,switch etc in my HA configuration.

This works for the majority of devices, but I have trouble with 3-4 of them. Some of them, like the one above, seem to be getting auto discovered and incremented on every restart of HA? But some are also not auto incremented and HA seems to think they’re legit but AppDaemon complains about them.

I also can’t seem to get rid of them. Destroying the mosquitto DB does nothing. deleting home-assistant_v2.db does nothing. These devices seem to persist across restarts of my hassio containers. The persist across reboots of the machine itself. I can’t git rid of them, and I can’t make some of them stop auto incrementing when I restart HA. What the hell is going on here?

They are probably stored in one of the files under the .storage directory. How they are getting there I do not know.

Yeah, it definitely has something to do with the .storage/core.entity_registry, but this just raises more questions than it answers.

He all of my devices define in the form:

  - platform: mqtt
    name: "Ceiling Light"
    unique_id: "livingroom_ceiling"
    state_topic: "hubitat/Living Room Ceiling/switch"
    command_topic: "hubitat/Living Room Ceiling/switch"
    brightness_state_topic: "hubitat/Living Room Ceiling/level"
    brightness_command_topic: "hubitat/Living Room Ceiling/level"
    brightness_scale: 100
    payload_on: "on"
    payload_off: "off"
    qos: 0
    optimistic: false
    retain: true

but core.entity_registry has this
            "config_entry_id": null,              
            "device_id": null,                       
            "disabled_by": null,
            "entity_id": "light.ceiling_light_3",
            "name": null,             
            "platform": "mqtt", 
            "unique_id": "livingroom_ceiling"                    

why the incremented entity id? Where are these auto generated ids coming from, especially since i have mqtt discover: false? Why are they overriding my explicitly declared devices?

I really do not know enough about the internals to be able to tell you.

Why not stop hass, delete the core.entity_registry entries and restart hass. See what happens.

Yeah that’s what I’ve been doing. I think I figured out what’s going on. The core.entity_registry seems to construct the entity id from the Name: field in the mqtt light device by lower casing and replacing spaces with underscores.

So Living Room Ceiling Light becomes living_room_ceiling_light. I thought the Name field was just friendly and it was using unique_id for entity_id. I’d already normalized “Living room” into livingroom in the unique_id, but since the entity_id was being constructed from the name it was constructing the entity_id as light.living_room_ceiling rather than light_livingroom_ceiling as I was expecting.

Sigh… I think I have it all sorted. I just have to replace the names in my groups and I should be good.

If “bedroom” and “bathroom” weren’t single words while “living room” and “dining room” are two words, I would have saved a couple of hours of confusion. Thanks English language.

warnings like these are generated when you use an entity name in 1 of your apps that doesnt exist.
for instance when you use listen_state, get_state or set_state with a none existing entity.

if you dont expect such a warning (you want that warning if you create a new sensor with set_state) then its always good to check in the state page in dev tools from HA.
never expect how an entity looks, but always check if its there and what its real name is. and for sure if you get those warnings.