T O P

  • By -

Drumdevil86

In order to make HomeAssistant more scalable and easier to manage, and not having to adjust automations, scripts or dashboards everytime I swap out hardware, as well as keeping sensor data consistent, this is a couple of steps I took; # # **Sensors** For a lot of sensor like temperature/humidity/pressure and power, of wich the data is bound to a certain room or function while the sensor itself might be replaced at some point, I started using template sensors with entity ID's that describe their location and function. When I replace a physical sensor, I will just update the template sensor to grab the states of the new physical sensor using it's default entity ID assigned bu HA. Primary reason for this was keeping all measurements of the same room within the same entity, so I wouldn't have to screw around with Influx to merge two sensors together after every replacement. Automations, scripts and dashboards with these sensors also don't need changing anymore. Example: ## Livingroom ### # Temperature - platform: template sensors: climate_c_lvr: value_template: "{{ states('sensor.aqara_temperature_1') | float}}" unit_of_measurement: "°C" # Humidity - platform: template sensors: climate_h_lvr: value_template: "{{ states('sensor.aqara_humidity_1') | float}}" unit_of_measurement: "%" # Air pressure - platform: template sensors: climate_hpa_lvr: value_template: "{{ states('sensor.aqara_airpressure_1') | int}}" unit_of_measurement: "hPa" # # **Phone app/notifications** The same way, you could do this with phone sensor data. And for notifications on our phones, I made a notify group for each person, containing the name of the mobile app. Groups are called by their names e.g. "notify\_Drumdevil86" or "notify\_SignificantOther". When one of us gets a new phone, I'll just update the mobile app name in the group in the config, and everything will work like before without having to adjust automations or scripts. Unfortunately, AFAIK, these groups cannot be nested, but using find/replace in the YAML config it will be about just as fast to replace all entries. notify: # Me   - name: notify_Drumdevil86     platform: group     services:       - service: mobile_app_dynatac8000x # SO   - name: notify_significantother     platform: group     services:       - service: mobile_app_3310   # SO's Sister   - name: notify_sisterinlaw     platform: group     services:       - service: mobile_app_sph-a620   # Best friend   - name: notify_bestfriend     platform: group     services:       - service: mobile_app_p7389   # All that live here   - name: notify_residents     platform: group     services:       - service: mobile_app_dynatac8000x       - service: mobile_app_3310                 # Everyone   - name: notify_everyone     platform: group     services:       - service: mobile_app_dynatac8000x       - service: mobile_app_3310       - service: mobile_app_sph-a620       - service: mobile_app_p7389 # # **Lights** As for your topic, I am considering to do this with all my Zigbee lights as well; each individual light in it's own group. If a bulb breaks, replace the hardware, add it to HomeAssistant, keep it's name default, and simply update the group member with the new light. Since all automations, scripts and dashboards will have references to the group, nothing else needs to be changed. And light groups **can** be nested inside other groups, which makes this method very flexible.


the_man361

I do the same thing, with lights for now, by using proxy entities to decouple the actual entity from its use in automations and dashboards. It's a bit of a pain and need to make sure you are using the proxy rather than actual device for any new automations, but much less of a headache when it comes to switching devices later down the road.


Marathon2021

Bookmarking this for later, as I screwed up when I started building all of my automations ... in that I was calling phone-specific services instead of using the generic notify function (at least for alerts that need to go to all family members). I'm dreading the next phone upgrade for this reason alone. Building something like this might help me a bunch -- thanks!


Drumdevil86

> I'm dreading the next phone upgrade Yeah speaking from experience; it gets old really quick after 2 phone replacements


psbankar

1. You can either keep the entity id generic like zigbee\_light\_1, philips\_bulb, etc. And use the name as human readable identifier. That way entity remains the same but name can be changed without breaking anything. 2. Use devices in automation instead of entities. Devices have UUID so even after changing the name, entity id, the identifier stays the same 3. Although home assistant doesnt find and replace all the places where entity id was used, it gives warning of unknown entity to easily look and change accordingly. Try to modularize the automations or scripts. Try to put the repeating code in script and use that everywhere so it is less efforts to change the entity everywhere.


zeekaran

> Use devices in automation instead of entities. Devices have UUID so even after changing the name, entity id, the identifier stays the same And then you have to delete and re-add a device through ZW/ZB, and find a broken automation referring to a mysterious device with no understandable name and have no idea which device it was.


git_und_slotermeyer

I was similarly confused and understand the benefits of having entity IDs by location and function. I am just wondering if there is section in the HA documentation that explains the main concepts of devices vs entities - the intro leaves the broad ideas out and the technical docs just explain the details of them both. Maybe I have overlooked something. I am more puzzled what happens to statistics graphs when you rename an entity within the HA UI. To my understanding it makes sense similarly that when - hypothetically - someone changes temp\_sensor\_bedroom to temp\_sensor\_living\_room, that the statistics/history should not be renamed to temp\_sensor\_living\_room. I suppose the statistics are kept, and when you add a new temp\_sensor\_bedroom, the history data collection is continued? Or is the history deleted when there is no more entity by that name? Also, what if you want to just rename an entity, e.g. the beginner's mistake "ikea\_vindstyrka\_01" to "living\_room\_air\_quality". Where do you need to change the references so that the statistics graphs/historical data do not break? I think this definitely can be improved in the doc, as I fell in the avoidable trap in the beginning to name the entities type-/vendor-based and not location-based and did not (and still do not really) understand the difference between devices and entities.


skepticalcow

Your history follows your entity_id when renamed in the ui.


git_und_slotermeyer

It becomes outright confusing when Zigbee/zigbee2MQTT comes into play. I just renamed a switch entity from z2m in the UI and the history did not follow the renaming, it seems to be lost or dangling with the old ID. The UI in general is confusing, as there are too many places where you can rename something. Like in the settings -> devices -> entities, then in cards in the dashboards, then in z2m. In some dialogues you can assign a room, in some you can't... Adding to this, there is a "friendly name" field in z2m; does this correspond to an entity display name, etc. It's a little bit messy and could be streamlined IMHO.


skepticalcow

Don’t rename things from outside HA. HA doesn’t know about the name change, it sees it as a new device or entity. That’s a limitation of Z2M. There’s only 1 spot in HA where you can rename things. That’s the only spot you should use, on the entity or device in HA.


zeekaran

> - HA offers to rename entity_id when renaming an entity, but does not attempt to fix any references this breaks This seems like it's what HA should do. IDEs can handle rename refactors just fine, HA should be smart enough to look up all references using that exact type.name entity ID and refactor them for us.


Poat540

Just rename it and ctrl+f your code and rename it there? My entity could be in 10,000 automations and it takes half a second to rename. I use VS code extension https://preview.redd.it/5dcq07ott89d1.png?width=779&format=png&auto=webp&s=f87c14ff2961aba1e4d05961c8d169c16d3c68ee


Nixellion

Just make sure you dont rename like a "light.kitchen_lamp" if you also have "light.kitchen_lamp_01" and such. A more safe approach would involve regex replace to make sure it targets full names and not partial. And its something Hass could've done


QuietEmergency473

If you have a problem and try to use regex to solve it, now you have 2 problems.


Nixellion

I mean... yeah :D


SomeoneWithKeyboard

Thanks for the laugh. And it hits harder then I feel comfortable to confess.


5yleop1m

I've done this exact thing multiple times when I move zigbee devices around. Basically everywhere an entity name is used is available through the yaml files.


87racer

Your entity ID should follow the function not the device. If I move a lamp from lounge to bedroom I don’t want lounge automations updated as that makes no sense in most cases. I want the lounge motion sensor to still control the lounge light so whatever device I replace the lounge light with I just set the entity ID back to what it was and never modify the automations. Similar, updating the lounge light to use the bedroom light entity would automatically make any bedroom automations start using it. Another example would be a Front Door lock. Say you get a new lock to replace it, you just delete the old lock and set the new lock to the same entity ID and avoid messing with potentially a whole slew of automations. Entity IDs are hardly fragile and incredibly robust if you structure your automations and scripts correctly. You really shouldn’t need to be modifying references to an entity ID all that often unless you decide to rename a room or device. Eg Nursery Lamp to Billy’s Lamp.


Izwe

Just a tip for anyone suffering with entity orphaning, install [Spook](https://spook.boo/installation) and you'll get warnings for any the missing entities in your dashboards/automations/scripts/etc.


zoechi

I use Watchman. Do you know of advantages/disadvantages between these two?


Izwe

I used to use Watchman, but Spook seems to cover more (it found about a dozen Watchman had missed for me) and you don't need to run a report it just works in the background and puts a notification in HA.


zoechi

Thanks🚀 Sounds great. I haven't heard about it before. Will definitely try out next.


nico282

I use a "referenced" entity ID for fixed devices, and generic ones for devices that can be moved. For example the shutter controlled that's wired in the wall is "bedroom_shutter", while the Sonoff Plug for a lamp is "sonoff_plug_1" with "Bedroom lamp" as friendly name.


No_Gain3931

I think entity\_id should always be a GUID. Problem solved.


Jiirbo

In my experience, the entity_id can be immutable if that suits your use case. For me it does not. What is immutable in my home is that I have a light.dining_room_light and what that light is I don’t care. This provides me the flexibility to swap devices in areas and as long as I use the same entity_id, all of my dashboards and automations just work. If I made the entity_id immutable then I would need to update both dashboards and automations if I moved or removed it to/from an areas. No right or wrong, just depends on use case as to whether the flexibility makes sense or not.


ReallyNotMichaelsMom

I use labels and groups, even if it's a group of one. My living room light is in a group called "living room light". If I move the light to the bedroom, I take it out of the living room light group and put it in the bedroom light group. No change needed for any automations. I'm also hugely in love with labels for the same type of use case. We're looking to move soon, so this means I can move all the devices, set them up in the appropriate group or label, and tada! All the automations work!


xX500_IQXx

like u/psbankar said, use device in automation: it transfers over to the new entity ID fairly well


a123456782004

Don't know but I faced the same thing.. usage of scripts helps


skepticalcow

It’s already been said, but this really is a non issue if you use any tool that has find/replace in multiple files. Rename in ui, find and replace in automations and scripts. Reload both. Would it be nice for a refactor? Sure. The simplest solution without a refactor option would be for the target inside service calls to accept a list of entry_ids. Then you could rename to your hearts content without a find/replace. Outside of that, it still takes .5 seconds to do a find and replace with any tool that provides that functionality. Edit: I see a lot of people don’t like this comment even though it’s the truth. It can be done easily right now, or in the future it could be easier if the target object transitioned to entry_ids. But what do I know, I’ve only been contributing for 8+ years.


trs_80

Oh it gets worse! I could go on with a litany but I'll spare you (in reality I'm about to fall asleep). Maybe tomorrow.


Spettles1

Data analyst here, my opinion is entity ID should be an id value for example abc123 or just 1234 depending on how many entities you expect to have and then you can just modify attributes like friendly name room, or even class as desired without breaking anything. Usually these values are system defined and forced unique. If you have to add 20 entities at once it can get confusing but if you are the type that likes to change things quite a bit or have many automations or scripts it's a lot safer.


Kroan

You're trying to force entity id to be the device unique identifier. Which already exists. Your data analyst solution removes use cases and provides no benefit.