Associating variable with sensors

Hello everyone,
I’m sorry if this is a silly question for most, but I’m still approaching to Home Assistant.

I’m accually trying to migrate as much automations as possible from my Homey Pro to my Home assistant installation.
At the moment I can control all the sensor I have on Homey (since some are from deConz and the rest is reached through MQTT).

On Homey I usually associate a state variable to each sensor (like if sensor A is open then set sensor A variable to Open" and viceversa), and then start to build all the automations using those state variables.

Doing that if I’ll need to change the sensor with a different model or reinclude it I’ll only have to set the new senser on the desired variable (that has all the associated automation) without having to fix every automation where the sensor is used.

Is it possible to do something similar on Home Assistant?
I’m not finding anything similar yet but I’m sure that I’m missing something.

You’d create template sensor for that kind of abstraction.

Example of mine

  - sensor:
    - name: "living_room_light_level"
      unique_id: "living_room_light_level"
      state: '{{ states("sensor.mi_light1_sensor")|round(1) }}'
      unit_of_measurement: "lx"
      device_class: illuminance
      state_class: measurement
1 Like

If that happens then all you need to do is remove the old sensor device and then add the new one. After that you only need to change the device name to match the old device and ensure that the entities picked up the correct entity_id’s to match the old ones as well.

If not then just edit those to match the old ones too.

So what you are trying to solve has already been built-in to the system.

1 Like

Wow that’s astonishing!
After reaing the template documentation I understand the scope of it even if I haven’t try it yet but for the purpose I was looking for (not having to fix a lot of automation when a sensor will break and I’ll have to change it) the entity_id swap is perfect!

I didn’t know that it was so simple!
Thank you to you both!

1 Like