How to replace defect dallas sensor

Hello,
I had a running ESPHome - HomeAssistant configuration where ESPHome reads a dallas temparature sensor and the resulting graph is shown in Home Assistant.
Unfortunately, the sensor died and only sends a constant value. Thus I tried to replace the sensor.
But whatever I do, Home Assistant always creates a new entity.

So the original sensor had entity ID

sensor.temperature_1

The new sensor has now entity ID

sensor.temperature_1_1

How do I configure ESPHome/Home Assistant in a way, that replacing a sensor does not change the entity ID on Home Assistant side.

My current ESPHome configuration look like this:

esphome:
  name: temperatursensor
  platform: ESP8266
  board: d1_mini
  project:
    name: "my.temperatursensor"
    version: "1.0"
  #includes: std_includes.h


# Enable logging
logger:
  level: debug

# Enable Home Assistant API
api:
  password: ""

ota:
  password: !secret OTA_PASSWORD
  safe_mode: false

wifi:
  ssid: !secret WLAN_SSID
  password: !secret WLAN_PASSWORD
  domain: .fritz.box
  fast_connect: true
  power_save_mode: HIGH

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: !secret AP_SSID
    password: !secret AP_PASSWORD

captive_portal:
    
# Example configuration entry
dallas:
  - pin: D1
    update_interval: 60s
    id: temperatursensor
  - pin: D2
    update_interval: 60s
    id: temperatursensor2

# Individual sensors
sensor:
  - platform: dallas
    #address: 0x843C01F095C69828              # address of old defect sensor
    address: 0xbd012212a8db2728               # address of new sensor
    name: "Temperatur Wärmespeicher 1"
    id: heizung_temperatur_warmwasser_1
    dallas_id: temperatursensor
 - platform: dallas
  #   ---- more sensors -----

As you see, the only thing I did was exchanging the address of the dallas sensor.

Have you restarted HA since you did the replacement?

What is the state of “sensor.temperature_1”?

if it’s unavailable (I assume) then if you click on the settings of that entity does it give you the option to delete it?

If none of that works you can try removing the device from the ESPHome integration and then let it rediscover it and it might fix it.

Yes, I did restart the whole home assistant server.

Uh, when I reviewed the settings on Home Assistant side for answering your question, I found some thing strange. I can see the following thing on Home Assistant Entity table:

The new sensor has following settings:

  • Name: Temperatur Wärmespeicher 1
  • Entity ID: sensor.temperatur_warmespeicher_1
  • Status: -
  • I can see current sensor data when opening this entity

The old sensor has following settings:

  • Name: Temperatur Wärmespeicher 1
  • Entity ID: sensor.temperatur_warmwasser_1
  • Status: -
  • I can not see any data when opening the entity. It only shows “This entity is not available”

So the entity ID is different for both. So when looking to my ESPHome sensor config, one sensor takes the sensor name as entity id, the other takes a part of the sensor id.
So I’m just wondering if I have messed up something when developing the ESPHome sensor script. And how Home Assistant identifies a sensor.

My main goal is, when changing a hardware sensor, I do not want to have a new entity ID in Home Assistant, so that a sensor replacement does never change the entity where the data are log. So I would have one graph showing the original data from the old sensor and then continues showing the data of the new sensor.

So what attributes finally identifies a sensor to Home Assistant? Is is the name or the id of a dallas sensor?

There may have been a change in how ESPHome creates the entity_id from the sensors. I’m not sure of that but I can see that happening with the way HA wants to change things like that. But it could very well also be a change in your ESPHome config (tho it doesn’t sound like it from your description).

If you open the settings of the old entity and open the advanced drop down at the bottom does it not offer an option to delete the entity?

if so then you can delete it there and then rename the new entity_id to the same as the old entity_id.

Just check that you’re not hitting the same issue as I had (took me a month!):

If something such as this happens (entity name extended by a “_1” because of the name aready did exist I do it this way.

Settings > Devices&Services > Entites
remove the old entry which is very likely unknown or missing or such like and therefore can be removed/deleted.
Then click onto the one with the unwanted “_1” at it’s end and simply rename the entity_id in the opened window (settings tab) by removing the “_1”. Press update and that’s it.

2 things to consider:
first keep Ronnies hint in mind, each Dallas got a unique id
second … keep yourself from defining names ending with “_1”
Simply because HA adds a “_1” if not being able to use the defined name if already being taken.
And it gets pretty hard to find out which one ought to end with _1 and which one accidently was given the _1 by HA.