I am implementing a light metering device to estimate PPFD and DIL (daily integral of light). It needs a reset at the end of each day so i set a real time clock based on sntp. Unfortunately the value of DIL is being reset to zero at random times.
I attached as much of the code as I felt was pertinent. Originally I had included a check that time minutes was less than 2 so that the reset of DLI would be only at midnight. That made no difference. I considered if a bad reading from the BH1750 could make a difference. A data validation test for lux_1 greater than zero made no difference.
It all looked simple enough until it didn’t work. Help would be greatly appreciated.
I don’t see a check for the time being valid so if the ESP reboots it might think it’s midnight before it gets a valid time.
Why wouldn’t you just use the integration sensor and use an on_time trigger in the time component for the reset? That shouldn’t trigger unless the time is valid.
The scaling of the sensor value can be done with a filter, so you could do the whole thing with no lambdas.
This is just what occurred to me when I sat down to make my monitor. Your suggestion is a good end run on whatever is happening here. I still would like to understand what went wrong. Unfortunately it sometimes take a whole day to find out what isn’t working. Thank for the help, I will give your approach a try.
I find now that the integrator does not reset at midnight. I also find that the integrator just continues forever rather than integrating for a day and resetting. Does the time function work at all? Perhaps I don’t understand the integration function, but it seems useless unless I can reset it to do periodic measurements.
I could certainly send just the lux value to home assistant and do all the work with a template, but it seems wasteful to not do the integral at the esp.
I gave up on using the time function in ESP home. I have to conclude that it is broken.
This solution, using home assistant as the timer appears to be working. I set up a time of day helper with an on period from midnight to four minutes after midnight, with the identity binary_sensor.midnight. I have verified that the integration is reset when the “midnight” helper is forced through the developers tools.