Check you are collecting the history on the daily_rainfall sensor, if there is no history being collected the statistics sensor can’t provide a value.
More questions is fine, I can’t guarantee I’ll have the right answer though.
Check you are collecting the history on the daily_rainfall sensor, if there is no history being collected the statistics sensor can’t provide a value.
More questions is fine, I can’t guarantee I’ll have the right answer though.
Oh, I thought that’s what the template was doing. Do I need to create an automation that collects the data each night at a certain time? That is definitely the issue if so. Because I don’t have anything else created other than the code/ screenshots posted last night.
If the answer to the above is yes, do you have an example you can show me.
Thank you for your conversation here, you have been very helpful.
Ok. So I just took a look at both the “historic rainfall” and “daily rainfall” shown in my earlier screenshot. It looks as if both have the value of yesterdays rainfall. So I believe writing to the sensors is happening properly.
“Historic rainfall” is my statistics sensor. “Daily rainfall” is the sensor I am storing the rainfactor day 0 rain to each time it rains based on the pattern you gave me in the template. (I believe this happens at midnight each night)
For Historic Rainfall, is “max_age” 24 hours ok? Below is the snippet from the statistics page regarding max age. I almost feel like I shouldn’t include it at all. The reason I say this is, if I am wanting an historic graph of rainfall, I believe it is deleting anything from the statistics sensors older than a day which means its only going to store one day and a time and discard all previous entries. What are your thoughts on this? I may be completely wrong (I believe the original code you sent me around the statistics sensor had this set at 48 but I’m thinking the same concept applies unless I don’t understand what I’m reading fully)
max_age time (optional)
Maximum age of source sensor measurements stored. Setting this to a time period will cause older values to be discarded. If omitted, the number of considered source sensor measurements is limitted by sampling_size only. Set both parameters appropriately to create suited limits for your use case. The sensor value will become unkown if the source sensor is not updated within the time period.
Thank you Peter for helping me get this going properly.
If you want to graph the data you don’t need the ‘historic rainfall’ statistics sensor just graph the daily rainfall using the statistical graph card.
I used the Statistics Graph Card
Lord. I’m an idiot.
I didn’t realize you could even do that.
I misread one of your earlier post with regards to the reason to using the statistics sensor. You were doing that as a way to group 48 hours worth of data. I read your usage of that completely wrong and that was the reason for the odd questions in the last reply. I had it in my mind, we were graphing using the statistics sensor.
Now I understand everything the way you intended.
Thank you for taking the time with me so that I know understand all of this.
Thank you so much Peter!! You have been immensely helpful!!
Came across this post through a search and figure it’s recent enough to hop onto it for some advice.
I’m also trying to make a “rainfall past 24hr” sensor but getting an inaccurate measurement with my statistics sensor. I have access to “precipitation yesterday”, “precipitation today” and “precipitation last hour”. I figured it would be as simple as using the statistics sensor and totaling the hourly precipitation sensor over a 24hr period.
sensor:
- platform: statistics
name: "Rainfall Past 24 hours"
entity_id: sensor.weatherflow_precipitation_last_hour
state_characteristic: total
max_age:
hours: 24
Today is the first real rainy day since setting this up. Precipitation yesterday was 0mm. Rainfall started today at roughly 8am. Total rainfall for the day is 16mm, but my statistics sensor is showing 45mm.
What I theorize is happening is that the rainfall past hour is updating continuously since the 1 hour window is constantly shifting through the day.
For example:
From 7-8am = 0mm
7:15-8:15am = 0.5mm
7:30-8:30am = 0.75mm
8am-9am = 2mm
And so on and so on.
The statistics sensor is doing exactly what it should do and totaling the outputs from the sensor. But since the sensor is updating more frequently than once an hour there is overlap and numbers are being added multiple times. So while total rainfall between 8 and 9am was 2mm, since the sensor updated at 8:30 and 8:15 the statistics sensor will be showing 3.25mm.
So I’m thinking this may not be the best way to approach this problem.
Is there any other way to tackle this?
I just installed this component and I get the following error:
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 442, in async_add_entities
await asyncio.gather(*tasks)
File “/usr/src/homeassistant/homeassistant/helpers/entity_platform.py”, line 717, in _async_add_entity
await entity.add_to_platform_finish()
File “/usr/src/homeassistant/homeassistant/helpers/entity.py”, line 813, in add_to_platform_finish
await self.async_added_to_hass()
File “/config/custom_components/openweathermaphistory/sensor.py”, line 215, in async_added_to_hass
await self._weatherhist.async_update()
File “/config/custom_components/openweathermaphistory/weatherhistory.py”, line 48, in async_update
localtimezone = pytz.timezone(data[“timezone”])
KeyError: ‘timezone’
Could this be due to :Replacing pytz with python-dateutil | Home Assistant Developer Docs
Hi @gregbm,
You must have a newer registration for OpenWeatherMap. This unfortunately does not support the history without signing up with payment details. Check out this Cannot setup - KeyError: 'timezone' · Issue #7 · petergridge/openweathermaphistory · GitHub.
I will try and spend some time to catch that error and put a friendly error message.
Cheers
Yes it is a new registration. I solved the problem by hard coding my time zone.
Can let me know where you hardcoded the time zone. I will update the notes on the repository for everyone else.
In module weatherhistory.py, line 48
localtimezone = pytz.timezone(‘my_time_zone’)
The other option is to take the time zone from the HA instance.
Thanks Greg,
I will look at making the change.
Cheers
I always get a little laugh out of the weather station argument. It makes you scratch your head and think “You think you need an array of sensor, conditions and automations to determine when some plants or the ground needs water”? Are we also going to be factoring in the soil or growing medium, time of year, the specefic needs of the different plants and so on and so on or is this more for fun? I’ve worked in the green industry for 15 years and seen all sorts of different attempts at doing this and none of them seem to be able to beat the 3 sensors on your head, your eyes and a little common sense.
How do you integratie your head sensors into ha?
If you don’t want to hobby with automating, you’re on the wrong forum
Hey Peter,
Hoping you or someone in this thread can give me a little help on my issue below (maybe I have missed an update or something that has caused this to start up?).
Below is what I am experiencing and I believe any background that would be needed to help troubleshoot.
Thank you again to anyone that can shed some light on how to fix this!:
I have the below error showing at startup that is related to my rainfall sensors (almost as if the sensor isn’t populating. Can someone help me figure out how to address this problem? I think the issue is that the day_0_rain is showing as “null” rather than a numerical value.
2023-06-08 11:32:02.652 ERROR (MainThread) [homeassistant.helpers.template_entity] TemplateError('ValueError: Template error: float got invalid input 'None' when rendering template '{{ state_attr('sensor.rainfactor', 'day_0_rain') | float + state_attr('sensor.rainfactor', 'day_1_rain') | float }}' but no default was specified') while processing template 'Template<template=({{ state_attr('sensor.rainfactor', 'day_0_rain') | float + state_attr('sensor.rainfactor', 'day_1_rain') | float }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.previous_rainfall'
Below is my sensor:
previous_rainfall:
friendly_name: "Past 48h Rainfall"
value_template: "{{ state_attr('sensor.rainfactor', 'day_0_rain') | float + state_attr('sensor.rainfactor', 'day_1_rain') | float }}"
And my daily rainfall sensor
- name: "Daily Rainfall"
#unit_of_measurement: "in"
state: "{{ state_attr('sensor.rainfactor', 'day_0_rain') }}"
state_class: measurement
Below is a screenshot of developer tools on “day_0_rain”. I don’ really understand what would’ve caused it to stop populating all of the sudden.
Thank you all again!!
Rainfactor sensor is also showing unavailable:
Additional info:
For some reason the below was commented out of my config
- platform: openweathermaphistory
name: "rainfactor"
api_key: !secret owmh_api_key
latitude: !secret owmh_latitude
longitude: !secret owmh_longitude
# unit_system: imperial
Also, after looking at the link below, I’m questioning if I am using the proper latest version (I usually update through HACS but not manually through going to individual repos and replacing files etc.)