Best way to make abstractions from entities

I want to create an abstraction from my physical devices to my logical devices.
For instance, a logical sensor could be “living room temperature” and the actual sensor behind it could be something like ‘sensor.0x006315611131_temperature’.
Then in my automations I will reference the logical sensor (e.g. living room temperature) and no the phyisical one.
What is it that I want to achieve? I want to be able to replace one physical device ( a bulb, a temp sensor, etc.) by another one and only having to change the config in a single place.

What’s the best way to do that?

What I have been doing so far is using this in config yaml files:

- platform: group
  name: 'Living Room Light'
    - light.0x7cb03eaa00af455d

Is this the right approach is there a better way?

1 Like

What I do is creating 1-to-1 template sensors exactly for that purpose, e.g

    - name: "living_room_temperature"
      unique_id: "living_room_temperature"
      # friendly_name: 'Living temperature'
      state: '{{ (states("sensor.ble_temperature_thermo_living")|round(1)) }}'
      unit_of_measurement: "°C"
      device_class: temperature
      state_class: measurement

1 Like

Yes, just rename the entity_id when replacing the device with something new.


  1. remove old device
  2. remove entity in the entity list if it still exists
  3. add new device
  4. rename entity_id for the new entity to the name of the old entity.

If you can’t remove the entity in step 2 (sometimes requires restart and I’m too lazy at that point) then do the following:

  1. rename entity_id attached to old device that you are planning to remove.
  2. add new device
  3. rename entity_id for the new entity to the name of the old entity_id.
  4. delete old device and no longer care about old entity_id until the next time you restart, which by then you will be able to remove.
1 Like

You can change the entity id in one place. Configuration / Entities.

Just change sensor.0x006315611131_temperature to sensor.living_room_temperature there.

And avoid using device automations, there is no easy way to change device ids like you can entity ids.

1 Like

I’ve never seen a need to make abstracted entities unless I’m changing something about the entity itself. Worse case scenario if you can’t do the steps I said is a find and replace in all your files. Which is very easy to do with vscode or notepad++.

That is the solution to the device id issue too.

Just to put it into perspective. I’m using 6 year old entity_id’s generated from the deprecated zwave on all my really old zwave devices.

now if you can’t change the entity_id because you’re using a really old integration that doesn’t allow changing of the entity_id, then I can see making abstracted entities. But these integrations should allow you to manually configure them and add name to the yaml. Which should change the entity_id, unless it’s a REALLY old integration.

Thanks for all your answers. I like both approaches and thanks to the answer from @koying I got to learn about Template Sensors, which I will use for also other things I didn’t know I could do.
I marked it as the solution because it provides exactly what I asked for, but the other answers I think are also really valid.

I find it more elegant to abstract a sensor usage rather than changing it’s name, really.

See it as dependency injection :grinning_face_with_smiling_eyes: