The value is decreasing sometimes. How to prevent this? I think this relates to recorder. Is there any option to keep the values or another simple way to create counter for lots of devices?
Make a template sensor that is 1 if the light is on, and 0 if the light is off.
Pass that into a riemann sum/integral helper, set to hours. That will give you a lifetime count of the amount of hours the light is on, and won’t use the recorder at all.
History stats is limited to the amount of data in your recorder, and can only really tell you how long it was on for the last ~10 days or whatever you set it to.
I have seen that the counter and its value are only increased when the status goes from 1 to 0. Do you know what happens during a restart or when the device is running 24/7? Do you know a way how I can still always get current values?