I have several history_stats sensors that I’m using to track my irrigation usage in order to calculate the cost of irrigating. Everything has been working great until today, they all went unavailable and I’m getting an error in my logs
Log error
Logger: homeassistant.components.history_stats.coordinator
Source: helpers/update_coordinator.py:223
Integration: history_stats ([documentation](https://www.home-assistant.io/integrations/history_stats), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+history_stats%22))
First occurred: 8:59:00 AM (4 occurrences)
Last logged: 8:59:00 AM
* Error fetching Both Drips Cumulative Runtime data: ValueError: day is out of range for month
* Error fetching Zone 2to14 Cumulative Runtime data: ValueError: day is out of range for month
* Error fetching Zone 15 Cumulative Runtime data: ValueError: day is out of range for month
* Error fetching Zone 1 Cumulative Runtime data: ValueError: day is out of range for month
Today is the 31st of May, I’m wondering if it being the 31st has something to do with it as it looks like the problem started at midnight. If so, how would I fix this?
You’re changing month first.
So the first replace is done and the date becomes 2022-06-31.... which is not valid so the rest of the replaces stops.
Move the replace month to last and it will work.
And as Tom pointed out, December won’t work.
Make it (now().month+1)%12 and it should work.
Well, now I have another problem. It’s now June 1st and my history_stats are showing “0”. The template is trying to calculate between the dates of 06/22/22 and 07/22/22. I want it to calculate the current stats between the 22nd of each month. So, currently 05/22/22 through 06/22/22. What am I doing wrong here?
From 06/01 to 06/22 it will correctly show me the stats from 05/22 to 06/22. But, from 06/23 through 06/30 it will incorrectly still show me the stats from 05/22 to 06/22 when I want it to show me the stats from 06/22 to 07/22
I want it to show me the 22nd of last month until the 22nd of this month. Ongoing, I want it to show me the stats between the 22nd of each month.
The code in post 8 shows the correct value when viewed from the 1st to the 22nd of each month, but the code in post 6 shows the correct value between the 22nd and the last day of the month. I’m using this to calculate my irrigation costs and not run the irrigation if I’ve gone over budget. So I need the stat to be correct on every day.
Wouldn’t this count the 22 twice in each period ? i would have had 22>21 … thou im kind of totally unable to compose a template, without “copying” and modify
Edit: never mind, just “remembered” a day starts at 00.01