snarky-snark / home-assistant-variables

A custom Home Assistant component for declaring and setting generic variable entities dynamically.
Apache License 2.0
274 stars 16 forks source link

[Feature] ~Add/~keep other attributes #91

Closed mdeweerd closed 1 year ago

mdeweerd commented 1 year ago

I try to duplicate a sensort that is updated without changes to the value, and for proper use I would also like to duplicate some attributes.

This is the original:

state_class: measurement
unit_of_measurement: °C
device_class: temperature
friendly_name: °C Contrôle Temperature

When I add manually the state_class and device_class to the state using the Developer Tools, these attributes are lost when the state is updated.

I would prefer that the attributes could be specified as part of the 'var:' configuration, or that unupdated attributes that are already present are kept.

mdeweerd commented 1 year ago

I just found that the extra attributes are "possible", but when I tried, I got null values for them just after reloading the "Variables" - it was ok after an attribute update:

var:
 salon_temperature_forceupd:
  friendly_name: "Température salon"
  value_template: "{{ states('sensor.ewelink_th01_temperature') }}"
  force_update: true
  unit_of_measurement: "°C"
  attributes:
    state_class: "{{'measurement'}}"
    device_class: "{{ 'temperature' }}"
    state_class_txt: "measurement"
    device_class_txt: "temperature"
  tracked_entity_id:
    - sensor.ewelink_th01_temperature
snarky-snark commented 1 year ago

You should use the var API to interact with var entities. Behavior of var entities modified via Dev Tools is unspecified.