enkama / hass-variables

Home Assistant variables component
90 stars 12 forks source link

Variable not acting as sensor #57

Closed franfos closed 1 year ago

franfos commented 1 year ago

This is more a question than an issue. I have a variable declared in yaml this way:

temp_dorm: name: T. Dorm value: 0 restore: true attributes: min: 99 max : 0 date_min: '' date_max: '' icon: mdi:temperature-celsius unit_of_measurement: "°C"

I'm updating this variable with the value of a temperature sensor. Everything works fine, but I realize that the card showing the information of the variable is different than the card of the sensor. It doesn't show the min/mean/max values. So it looks it's not treating this variable as a sensor (with long term statistics and so on). Is is due to the yaml definition or a restriction of the variables themself?

Snuffy2 commented 1 year ago

You want to add device_class and probably state_class attributes.

temp_dorm:
  name: T. Dorm
  value: 0
  restore: true
  attributes:
    min: 99
    max : 0
    date_min: ''
    date_max: ''
    icon: mdi:temperature-celsius
    unit_of_measurement: "°C"
    device_class: temperature
    state_class: measurement

It may not work 100% like a sensor, bu tit should be a lot closer. I'm working on an update now to better support all of the different sensor (& binary_sensor) device_classes, state_class. It will be part of the UI though and likely not brought into yaml.

franfos commented 1 year ago

Thanks for the suggestion. First, I changed the yaml file as you said but it didn't work. So I dig into core.restore_state file and also changed there the attributes of the variable. After restarting and refreshing the browser, now the measurements are shown as a "true" sensor. Great, The problem I guess is that I can't migrate them to UI definition until you make the changes you mentioned, right?

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.