Closed GLehnhoff closed 1 month ago
I suspect it won't survive, I never programmed it to do that. I'll take a look.
In my scenario I also need the value to survive a restart. I want to use the virtual sensor to split power measurements into different tariffs & can't use utility_meter as I don't want a cyclic reset. But as the virtual sensor resets on a reboot, I can't use this either.
@tnagels I have a “Start Up Automation”. This is essentially composed of scripts that perform basic functions upon start up.
For example, I use virtual switches as “conditions” in automations. Such as “ENABLE Outdoor Timers”. If I do not want my lights to turn off in the normal 1 hour, etc then I flip that virtual switch (which is a condition of my automation).
Now, to answer your question. I have a script that turns on all my virtual switches on startup EXCEPT my “Vacation Mode” virtual switch. I hope this made sense and helps!
I could use this one too! Your integration is very useful to me (I use it to replace light groups) and having persistent value would be a must....
I would have help, but I never used python...
I will take a look at this. Home Assistant has a storage package I can use.
I could also use this, I use this to keep some states, enable night mode in the house, etc... It would be useful to keep the state when home assistant reboots.
I'm not a python coder (I would have help), but I'm à coder, and I tried to read the developer doc... I didn't see any storage API.
The history API could have help (get the last known state which is not unavailable), but the history can be disabled...
The most reliable way would be, in my opinion, to store a virtual.yaml file (or JSON, or any format) in the config folder, storing the virtual devices serialized, and updated each time a device's state is updated, file which would be loaded at startup to restore devices' states (and checking if any device has been removed or added)...
My 2 cents... 😉
Many of the use cases for the virtual components can be achieved by the HA built in template components. The only thing missing there (at least for me) is for the state to stay persistent after restart, when the state can't be rendered. That's why I am hoping that the virtual components get this feature, as there are many use cases for that. Any update on that?
I just migrated all my light templates to virtual components thinking they would be easier to use and I stumbled upon the issue that they don't keep their state on reboots! Is there any workaround to solve this? Thanks :)
This issue is stale because it has been open for 365 days with no activity. This issue will be automatically closed within 28 days if there is no further activity.
This issue was closed because it has been inactive for 28 days since being marked as stale.
Hi. It seems that the value of a virtual variable is not surviving a HA restart. Is this true and if so, is there a workaround available? Or is my setting of "initial_value" my problem? Cheers, gl