rogro82/hass-variables

Use custom Unit_of_measurement with variable

Opened this issue · 3 comments

I use the variables to feed data into Home assistant from local sensors and different apis. For example I have a temperature / humidity sensor, which is updating two variables when it gets an update.

However, I want to show the unit in the UI. How can I set a unit of the variable in use?

I have this:
grafik

I want this (shot from other SH system):
grafik

I don't think it's possible to assign a unit of measurement to a variable (treat it like a usual "variable" in a programming language), but you can setup a sensor like:

sensor:
  - platform: template
    sensors:
      temperature:
        value_template: "{{ states('variable.temperature') }}"
        unit_of_measurement: '°C'
\

It should be possible as unit_of_measurement is an attribute and you can set the attributes of the variable.
The issue is currently the variable don't restore the attributes after a reboot if you need this.

Good news the attributes will be restore if the #32 is merged.