hass-variables icon indicating copy to clipboard operation
hass-variables copied to clipboard

Use custom Unit_of_measurement with variable

Open georg90 opened this issue 6 years ago • 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

georg90 avatar May 01 '19 08:05 georg90

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'
\

OleksandrBerchenko avatar May 14 '19 13:05 OleksandrBerchenko

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.

oncleben31 avatar Jul 22 '19 20:07 oncleben31

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

oncleben31 avatar Jul 24 '19 07:07 oncleben31