I feel a bit foolish asking for help with this but here goes. I want to know for how long each month the tide is below a certain height. I thought I could create a helper-timer and just start/stop it but that does not accumulate. This is what I tried (2 automations):
Thanks, I knew there would be a neat solution I can learn from the experts!
Does this look right to you? I’m asking becuase it will take weeks to accumulate any results:
Just be aware of the need to extend your recorder duration for the history_stats sensor, as on the page. As a test, you could also record the amount of time that the sensor is off to make sure it’s accumulating.
I’ve now got this is configuration.yaml but neither sensor is visible in developer tools: states after reloading all YAML configuraion. Is this because time has to pass?
Hmm. The one that is supposed to be accumulating the off time is still reading zero 5 mins after creating it.
Also, the binary_sensor gets switched on during a YAML reload or system restart, until sensor.tide_height_now gets a value. It’s only a short time, but it would be good to stop this.
Your database will now store 61 days worth of activity for every entity in your system. That’s not the most efficient way to keep a record of a month’s worth of tide height.
In addition, you have configured your History Stats sensor to use last month’s data … which doesn’t exist yet because you (probably) haven’t been recording it for such a long time period (until today when you changed the retention period).
I suggest you:
Revert purge_keep_days to its original value (default is 10 days).
Re-configure the History Stats sensor to record just one day’s total time.
start: "{{ today_at() }}"
end: "{{ now() }}"
Use the Utility Meter integration to create daily/weekly/monthly/yearly sensors (your choice). It stores its data in a database table that’s never purged.
I provided an example here for another user who wanted to record total heating time on a daily/monthly/yearly basis.
The suggested solution is far more efficient and will record tide height data starting from today (i.e. you can’t go backwards in time to access data that was never recorded).
Thanks for that. It’s only been running a short while but I’m getting a small number despite the sensor being “off”. This is what I’ve got now:
configuration.yaml:
It’s reporting that binary_sensor.slwisrestricted has been on for about 7 seconds today (more precisely, “today” starts at the time when the History Stats sensor was created).
If binary_sensor.slwisrestricted has been on for longer than 7 seconds (since the History Stats sensor was created) then, yes, there may be a problem with how you have configured it.