Closed cipacda closed 7 months ago
I think this is now fixed in the latest dev version of the var component, if you're willing to give it a try.
I am on the latest release, but I was setting the state wrong. Now I have the state being persisted, but the attributes are lost.
I think that works as well, but you need to have the attribute set in the config, you cannot set new/dynamic attributes as those will not be persisted
Just a few minutes ago, I made a potential fix on the develop branch.
Thank you for the quick attempt. That did not seem to work though. The attributes seem to be reset on restart :(
Any progress on this? I can't find any reason at first to remove the attributes on reboot
Can you explain your problem and include a minimal reproducible example?
var:
attr:
attributes:
test1:
test2:
attributes test1 and test2 will survive reboot in this case
but we want to skip attribute declaration in yaml. Just declare
var:
attr:
then set var.attr.test1 and var.attr.test2 dynamically from pyscript or automation. In this case all attributes not survive the reboot.
I use attributes of var.attr as quick dynamic variables, because don't want to declare new variable each time.
Thank you. I think I see what the problem is.
@snarky-snark Any progress on this issue?
I want to track battery replacement dates as sensor sttributes in a variable with a date which I want to var.set
when the bettery gets replaced. The problem I have is...
a) If I dont define the attributes in my var.yaml they do not get restored.
b) If I define them then they acquire the value that I am forced to set in var.yaml and then I cannot change them.
Defining this way they do not restore:
batteries_replaced:
friendly_name: Batteries Replaced
unique_id: batteries_replaced
restore: true
Defining this way they are fixed and cannot be changed:
batteries_replaced:
friendly_name: Batteries Replaced
unique_id: batteries_replaced
restore: true
attributes:
sensor.front_door_lock_battery_level: ""
sensor.garage_2_battery_level: ""
sensor.garage_3_battery_level: ""
sensor.garage_door_battery_level: ""
sensor.laundry_room_battery_level: ""
sensor.garage_door_lock_battery_level: ""
sensor.4_in_1_multisensor_battery_level: ""
sensor.front_door_multisensor_battery_level: ""
sensor.garage_1_battery: ""
sensor.office_battery: ""
sensor.bedroom_battery: ""
sensor.kitchen_battery: ""
sensor.bathroom_battery: ""
sensor.button_1_battery: ""
sensor.landing_2_battery: ""
sensor.front_porch_battery: ""
sensor.landing_1_5_battery: ""
sensor.living_room_battery: ""
sensor.powder_room_battery: ""
sensor.south_patio_battery: ""
sensor.kitchen_mijia_battery: ""
sensor.outside_weather_battery: ""
sensor.southeast_patio_battery: ""
sensor.southwest_patio_battery: ""
sensor.rear_smart_timer_battery: ""
sensor.front_smart_timer_battery: ""
sensor.phillips_hue_switch_battery: ""
and defining this way the integration fails to load:
batteries_replaced:
friendly_name: Batteries Replaced
unique_id: batteries_replaced
restore: true
attributes:
sensor.front_door_lock_battery_level:
sensor.garage_2_battery_level:
sensor.garage_3_battery_level:
sensor.garage_door_battery_level:
sensor.laundry_room_battery_level:
sensor.garage_door_lock_battery_level:
sensor.4_in_1_multisensor_battery_level:
sensor.front_door_multisensor_battery_level:
sensor.garage_1_battery:
sensor.office_battery:
sensor.bedroom_battery:
sensor.kitchen_battery:
sensor.bathroom_battery:
sensor.button_1_battery:
sensor.landing_2_battery:
sensor.front_porch_battery:
sensor.landing_1_5_battery:
sensor.living_room_battery:
sensor.powder_room_battery:
sensor.south_patio_battery:
sensor.kitchen_mijia_battery:
sensor.outside_weather_battery:
sensor.southeast_patio_battery:
sensor.southwest_patio_battery:
sensor.rear_smart_timer_battery:
sensor.front_smart_timer_battery:
sensor.phillips_hue_switch_battery:
I have successfully replaced this home-assistant-variables integration with the Variables+History integration (hass-variables) and it's working perfectly. You can dynamically add attributes and they survive a restart if Restore on Restart
is true. Plus, no yaml required as it is all configured in HA Integrations frontend.
I have a variable for which I set some attributes dynamically from a custom frontend panel, but the attribute gets lost after each restart or variable reload.
Here is my config