Best procedure to replace a failed device

Thanks gents. I thought I had a spare but apparently I don’t so it’ll be a day or two before I can try this out but it sounds easy enough (even for an old f**t like me). :slight_smile:

So this turned out to be a complete PITA. After copying the ESP home device configuration and saving it somewhere safe, I deleted the device from ESP Home by clicking the 3 dots and selecting “delete”. Counter intuitively, this does not delete the device when one looks at settings - devices and services - integrations - ESP home. So I selected the device from there as well and hit delete again (which is what Jos said to do). Then I restarted HA. I also deleted the device from my Router - just in case that got confused when I created a new WiFi device with the same name. Not sure if that was necessary but “belt and braces” and all that…

Then I flashed the new device with the original configuration. But then when I looked at my lovelace dashboard, most of the entities were showing as not being available. Further investigation showed that they had been changed and given new names. So for example “sensor.study_slats_position” became “sensor.study_blinds_study_slats_position”. i.e. the entity name seems to have the device name added to it. There are quite a few entities scattered across multiple tabs so changing all of these was a complete PITA. I tried going into the device and adding the various sensors and controls to the dashboard from there but all that seemed to do was create new cards.

So having changed all the entity entries on my various dashboards and tabs, I then had to go through every automation and find the ones which used entities from this device, because they all referred to the now defunct and non-existent entities from the old device. So none of the automations worked either.

All in all, this was not a good experience and has taken my about 3 hours on top of the time it took to flash and instal a new device.

So here is a suggestion. How about an option within ESP home for “Replace Device” as well as “Add new device”. I would envisage it working something like the user connecting a new board then selecting the device to be “cloned” and ESPHome / HA would just take care of the rest, and either retain all the old entity names, or change the dashboard and automation settings to use the new names.

We did not tell you to do that.

Ah. Yeah, ESPHome adds the device name to the entity id now. But only if you include a friendly_name in the config. This is a recent addition I forgot about.

All you had to do was delete the friendly name from the config and delete and re-add the device (in home assistant - not the ESPHome addon).

Thanks. To be clear, I said that I deleted the device from BOTH settings - devices and services - integrations - ESP home AND from the ESP home add on. Are you saying that I should explicitly NOT delete the device from the add-on as well as HA? It sounds rather counter-intuitive to someone such as me who is less proficient in these things.

Yes that is right. You only need to delete the home assistant integration, not the device configuration from the addon.

Just FYI

The addon is solemnly used to compile and upload the esphome binaries, but after that the add-on is not required anymore (so basically the add-on has nothing to do with the HA integration with esphome devices :thinking:)

Sone people use a stand-alone esphome installation, and don’t use the addon :wink:

Ummm, getting back to this “friendly name” thing, I’m not sure that I understand. I had used “Name:” here and there in the ESP home device config but not “friendly name”. Are they one and the same thing? Here is a section of the file:

switch:
  - platform: gpio
    pin: GPIO23 
    name: Blinds_Fault
    id: blinds_fault_light
  - platform: restart
    name: "Study Blinds Restart" 
    
sensor:
  - platform: template
    name: "Study Blind Position"
    id: blinds_position  
    
  - platform: template
    name: "Study Slats Position"
    id: slats_position
 
  - platform: adc
    pin: GPIO34
    name: "Study Sun Brightness"
    id: study_sun_level
    attenuation: 11db
    update_interval: 5s  
 
binary_sensor:
  - platform: status
    name: "Study Blinds Status"    

So are saying that I should have deleted all those “names” eg, “Blinds Fault” and just used the ids? If so, what about the binary sensor “status” which has a name but no id? Should that have been given an id instead of a name?

Thank you for your patience and sorry if I’m being thick here.

No they are not the same thing. Check the link I posted.

Ahh, that’s what was confusing me. With the original configuration, I never used “friendly name”. This got inserted when I first configured a new device and I never noticed it. For some reason, I only copied the original configuration from after the “name, platform, board” section so that new “friendly name” persisted.

So if I’ve got this right, then the procedure should be as follows.

  1. Copy the device configuration using a text editor such as notepad++ and save it somewhere safe.

  2. Delete the device from Home Assistant - Settings - Devices and Services - Integrations - ESP Home. (Note deleting the device from the ESP home addon won’t work).

  3. Restart Home assistant.

  4. Prepare a new device in the normal way.

  5. Copy the saved configuration to the new device.

  6. If the original saved configuration did NOT have a “friendly name”, delete any reference to “friendly name” which might have been added when the new board was created. The reason is that later versions of ESP Home add a prefix “friendly name” to the entity IDs so if one did not originally use “friendly name” then the entities that get added to Home Assistant will be different to those which are used in the dashboard and any automations. If the original file DID use friendly name", ensure that it matches the new configuration.

  7. Validate and install the new configuration in the normal way.

Does that cover everything? If so, then I’ll mark this as being the solution for future reference for my own benefit and other, less proficient users like me.

Thanks again for all your help and patience.

  1. Not required. This will not be affected. The addon data is completely separate from the integration.
  2. Yes.
  3. Yes.
    3a. Check the entities are gone in the entity list.
  4. Yes.
  5. You can use the file from step 1.
  6. Yes.
  7. Yes.

Does this procedure preserve home assistant history for entities?

Yes, have been doing it recently several times when upgrading some modules.
It will only happen automaticaly if the entity-id’s in HA stay as they were in the old device. I sometimes had to modify some id’s to be identical to the old entity-id. You can find their old id as unavailable in the “Statistics” tab of the Development tools after removing the device from the EspHome addon. (Just note their id’s and DO NOT delete them from that Statistics list of course.)
Any “Friendly name” of a device will play tricks with entitiy-id naming. That’s why tom_l hinted to delete it in the yaml.
So, what I do:

  1. Delete the device from the EspHome HA integration (NOT from the EspHome addon = where you compose your yaml.)
  2. Take note of the old entity-id’s in “Statistics” where they appear as problem entities for the time being.
  3. Connect the new device through USB and upload the existing firmware to it (after having modified the yaml to work with the new hardware if required.)
  4. Wait for the device with it’s entities to re-appear in HA or add it manualy if that does not happen automaticaly.
  5. Modify their id’s to be the same as the old ones if you want to keep and continue their history.

Okay, for somebody struggling like me,
delete device from the EspHome HA integration (NOT from the EspHome addon = where you compose your yaml.) means that

  1. You go to settings → devices and services → integrations tab
  2. click on esphome HEADER (and not devices link). there you will see list of devices and three dots next to it will let you delete as described.

This is hideous ux, and you cannot delete device from actual device page for some reason.

1 Like

Ummm… So step 5 you say use the file from step 1, but you said step 1 wasn’t required. So it looks like I have to set everything up all over again…

Is there really no simple way to replace a broken device and have it function like the old one?

Step 1 isn’t needed because you do not delete the device in the add-on. If you do not delete the device in the add-on then you still have your YAML

OK. I’d never heard of the add-on, only the integration. Sometimes I feel like I’m making progress with HA, and then I feel so lost again. I’m not complaining - I realise that for something to be very flexible and powerful then complexity is unavoidable - but it feels like the learning curve on this never flattens.

Your are correct

so, i replaced an esp by

  • deleting in HA
  • downloading firmware
  • flashing new hardware
  • readding to HA

which replaced everything as expected on the dashboards - but oddly not in the automations which use entities of this device giving the

Error: Unknown device ‘3dc48263some-kind-of-hash’

but since this kind of hash is nowhere to be found hence not easily replaced - how can i get the new device to use this (or change to the new one in the automations)?

tia.

@drahdiwaberl

this made me think - as i actually never ever am using device_ids in automations, why i even don’t know what they look like.

but surprisingly i found that there was one ‘Device action’ in each of these (rather complex) automations which were shown ‘empty’ in the UI editor - and checking the automations.yaml there indeed were these kind of device_id/entity_ids.

no idea where they came from.

thanks.