snarky-snark / home-assistant-variables

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

Only state is restored, not "set" attributes #116

Open NateEaton opened 4 months ago

NateEaton commented 4 months ago

My use case involves having a list of attributes that are set in an automation with each being the name of a battery sensor and the date it was changed. The automation also sets the value of the variable to the latest sensor/date set as an attribute.

However, after a restart of HA, the state is restored but the only attribute restored is the one defined in the initial configuration (Friendly Name).

I am not sure whether this is a bug or a feature request as the documentation only references state, not attributes, but it seems reasonable to expect that both would be restored.

estegewr commented 4 months ago

Up to version 0.15.0, I was able to restore attributes by initializing the attributes in the configuration file to an empty string. I think that this was more of a side effect and not a planned behavior. Since version 0.15.1 this is no longer possible. Therefore I would like to join the feature request. Restoring attributes in the same way as status values would be very helpful. if it simplifies the implementation, I would also name the attributes to be restored in the configuration.

amandatennent commented 3 months ago

I came across this issue as well, my work around (in case anyone else finds it helpful) is to create a script and have it run on home assistant start up

estegewr commented 3 months ago

Where do you get the values to restore them in the init script, @amandatennent?

amandatennent commented 3 months ago

I guess my use case is different, the attributes on my variables are static and aren't modified after they're created. I mis-read the initial issue.