Is there a better way to replace a device?

Occasionally, a device needs to be replaced. Recently, I replaced an Aqara door sensor that went bad, and there were a couple of automations that I had to manually fix.

My hope was that if I renamed the original from “gate sensor” to “old gate sensor” and gave the new one the original name “gate sensor” that HA would figure it all out. Instead, it looks like HA updated the automations when the old device was renamed so it was still pointing to the old Aqara’s entities.

Is there a different process I should have followed? It seems like there should be a way to finesse this to avoid the manual editing.

(BTW, the similarly named topic from 2022 involves Node Red and added abstraction layers that didn’t apply here.)

1 Like

Welcome to my pet-peeve. Your new device is named “gate_sensor_2” and you have to edit any automation or script that refers to “gate_sensor”.

You can delete the old entity first, but if it appears in any automation, you can’t delete it.

My solution is to use grep (AstroGrep on the PC) to find everywhere that “gate_sensor” appears in your config folder.

1 Like

You could have done that as long as you never used device ids, only entity ids.

See: Why and how to avoid device_ids in automations and scripts

I just replaced my Aqara shed door and gate sensors with zigbee 3.0 versions of the contact sensor. No issue at all. Renamed old sensors (in zigbee2mqtt) then added the new sensors with the old names. No other adjustment required.

1 Like

When I have done this in the past, I delete the old device, and make sure its entities have gone. Then add the new device using the old devices name. Works fine with zigbee, but can sometimes not work so well with ESPhome stuff.

1 Like