I was going through the long rain gauge thread and followed a link to this project page. From here, I printed the enclosure and added the Aqara door sensor, calibrated the device, and added code to HA and waited for rain. I can see state changes in HA (under MQTT using Z2M) as the sensor opens and closes. The problem I’m having is that the code doesn’t seem to be counting the changes so accumulation is never reported. I’ve been looking at this for weeks and can’t figure out what I’m missing (but it’s clearly something simple).
I actually don’t see why you wouldn’t be getting a non-zero value if your door sensor is actually changing states. Depending on how much you’ve changed this code you may want to restart HA, clear your browser cache, and verify (using developer tools-> states) that there aren’t duplicate entities ending in _2 on your system.
But i would recommend against the setup you’re attempting to get working anyway. The history_stats ‘count’ function will count matching states, but what you need instead is to count state transitions. Let’s say the door sensor has not tripped at all in the last 24 hours. The history stats counter will return 1 because the sensor matched one state. Even though the bucket never tipped a single time. In other words your sensor will never report less than 0.53mm of rainfall.
Here is a setup that does what you want. You’ll get a total rainfall sensor (total all time) and then using the statistics platform you can calculate the previous 24 hours rainfall.
We’ve been under drought conditions since I first posted but had a torrent of rain today (and I’ve been too busy and/or lazy to manually move the sensor). Seems like the recommended changes worked as expected, greatly appreciate the code and knowledge.
I’m unclear why the previous dry days are now showing 11.58mm of rain. Could this be stale data that’s displayed in the place of a zero reading? Would the purge_keep_days, as suggested by @parrel, be needed somewhere in the code?
Seems like the stats do not get reset which is more of a problem (since I wanted to use this reading to disable irrigation). I haven’t had time to re-review code in the original thread which likely has the answer.
If you’re looking for a daily total, create a utility meter helper using your total rainfall sensor as the source. You can choose the reset cycle, which of course you’ll want daily
I believe I’m just getting dumber the more I dig into this. I created a helper to test resetting the daily value and that should occur tonight. The cumulative value is still being reported but, although we had rain today, there was not 6+ inches of rain tonight.
It’s not clear what sensors you have and how they are configured. Can you post the yaml for whatever ones are configured in yaml, and also describe the ones that are configured in the UI?
Can you show the graph for the “rainfall total” sensor over the same time period as the “rainfall test” sensor? They should both increase by the exact same amount, the only difference is one resets to zero each night.
The rainfall total sensor appears to be working correctly. How did you configure the utility meter helper? Did you make sure that the “delta values” option remained disabled?
The data looks good when using a helper but still unclear on how to reset the cumulative count of the rainfall_total. Will it just keep historic data of rainfall since it started tracking?
Correct, it will never reset. Think of it like your electricity meter or water meter. The magnitude of the number is irrelevant, all that matters is how much it changes over a period of time.
It is possible, if you really want, to modify the template sensor so that it will reset that number on some fixed schedule or via an automation. But I would advise against it and instead recommend you add utility_meter helpers for any cycles that you want to reset on.
Thanks so much (again) @mekaneck for your patience and thorough explanations. I’ve had HA running for years but always learning (and re-learning) as new requirements come up and new features and functions are added.
Now on to see if the automation that disables the irrigation after X amount of rain is working