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

Restore attribute values if HA starts #112

Closed estegewr closed 4 months ago

estegewr commented 5 months ago

The default behavior of the module is to restore the variable value after HA restarts, whcih can also be requested with the restore option in conguration.yaml

var:
  weather_forecast:
    friendly_name: "Weather forecast for next 8 hours"
    restore: true

While HA is running, I set the variable value and some attributes with the service call:

service: var.set
data:
  entity_id: var.weather_forecast
  value: sunny
  attributes:
    TempMax: 20.1
    TempMin: 11.4

Value and attributes are set successfully. But HA restart will only restore the value, not the attributes With a trick, you can also get this done: By setting an initial value of the attributes in configuration.yaml:

var:
  weather_forecast:
    friendly_name: "Weather forecast for next 8 hours"
    restore: true
    attributes:
      TempMin: ""
      TempMax: ""

This was probably not the intended way in which the initial setting of the attributes had played out. Starting with v0.15.1 and still in 0.15.2 each HA restart initializes the value of the attribute with the configured value in configiuration.yaml. Unfortunately, this also means, that I cannot restore any updated attribute.

Therefore, I would like to ask for a configuration option to define attributes for further proceeding/restoring if this cannot be figured out automatically browsing through all available non-standard attributes.

LiloBzH commented 4 months ago

Hi

same issue with my printer. After reboot of HASS, value are null

Exemple for black

  epson4200black:
    tracked_entity_id: sensor.epson_xp_4200_series_black_ink
    value_template: >-
      {% if is_state("sensor.epson_xp_4200_series_black_ink" , "unavailable")  %}
         {{ states("var.epson4200black") }}
      {% else %}
         {{ states("sensor.epson_xp_4200_series_black_ink") }}
      {% endif %} 
    friendly_name: "Epson XP-4200 Noir"
    unit_of_measurement: "%"
LiloBzH commented 4 months ago

EDIT : it's ok after rollback to 0.15.0

0.15.1 and 0.15.2 seem to be broken

dscottbuch commented 4 months ago

I can confirm the same behavior. States/values were not being saved across restarts with 0.15.1 and 0.15.2 but rollback to 0.15.0 restored this behavior

snarky-snark commented 4 months ago

Try v0.15.3.

LiloBzH commented 4 months ago

patch ok for me ! :)

LiloBzH commented 4 months ago

just for information, I see a different number version : v0.15.1.3 (and not 15.3)

snarky-snark commented 4 months ago

Agh, typo. Should be fixed now.

dscottbuch commented 4 months ago

Thanks worked for me also. Scott BuchananOn Apr 17, 2024, at 4:04 PM, snarky-snark @.***> wrote: Agh, typo. Should be fixed now.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>