Hoping to get a little help on getting "today rainfall", "yesterday rainfall", and "past 48h rainfall" into a sensor in my Home Assistant instance

I currently have the following weather integrations installed within my home assistant instance and was somewhat hoping this could be done without adding an additional integration. If not, I am ok with adding another integration but was hoping to go with the “less is more” approach for this.

I currently have the following weather integrations installed:

Accuweather
Meteorologisk (Met.no)
Weatherbit
Pirateweather

It would be nice if I could get “today rainfall”, “tomorrow forecasted rainfall”, “yesterday rainfall”, “last 48 hour rainfall” and “last 7 days rainfall”

My goal will be to pass some of them into the below code. (I am very new to home assistant, and stole the below from the slacker labs repo)

      # yesterday_rainfall_in:
      #   friendly_name: "Yesterday Rainfall"
      #   value_template: "{{ state_attr('sensor.daily_rainfall_in', 'last_period') }}"
      # previous_rainfall:
      #   friendly_name: "Past 48h Rainfall"
      #   value_template: "{{ states('sensor.daily_rainfall_in') | float  + state_attr('sensor.daily_rainfall_in', 'last_period') | float  }}"

Thank you all for any help/ teaching you can provide with this one!!

Just for my understanding, you want to compare forecast? As putting a figure into a past date might lead to assume that this was actual rainfall…

An option is that you could put these value in input_helpers
Input Number - Home Assistant (home-assistant.io)

@vingerha thank you for your response.

No, I’m not wanting to compare forecast, sorry for not being clear enough. I would like to add historical rainfall totals to my home assistant instance in some way to help with garden watering and I haven’t been able to find a good source for reliable data.

For now I am using the following which is a connection to openweather:

It is only capable of giving me the past 5 days rainfalls on a per day basis. Worst case, this will probably be good enough even if it is a bit crude.

I am definitely still open to other ideas though. Thank you all!!

Still not completely getting the use case but…that is just me.
So you want to store historical actual (!) rainfall based on ‘something’ e.g. the link sent.

What if you create a (template( sensor to store daily actual rainfall, then you could use this for your whatever you are set to do? The trick will be that HA recorder purges normal sensor data after x days (recorder settings) so you would have make sure to make it part of statistics.

Exactly.

The “something” is the biggest problem. I can’t find a free source that produces this data but more importantly, sadly I’m not a programmer so I have been trying to find already produced solution that would just require setup on my home assistant instance. (I would rather not set up my own rain tracking hardware/ ground moisture meters)

The previous link has been the best I could come up with so far.

I follow you and am familiar with this.

So as long as whatever is decided on, make sure it is stored or uses the statistics integration and I won’t have to worry about it purging the rainfall data?

So I believe this may be what I have done. Below are some screenshots and code, I can already tell that you know more than I do about this stuff so thank you for giving me guidance and your thoughts.

The question I have is, how can I keep this working properly if it is only storing 5 24 hour periods of rainfall. And the periods start at the time of the day that the integration was last updated. Not on a daily basis.-- This is one of the reasons, I really feel like I need a better data source that is date based rather than what it really is (as described above).

We (not just me) can help with the programming but we cannot invent the source that you are happy with, so you have to indicate a direction and then see if it works out
On the sensor, from where I see this right now … you would only need one sensor and update this daily with ‘today’s actual rainfall’ and properly make it part of statistics, no need to have thie attributes as per picture above. it would then gradually allow you to create an overview of past rainfall.

Im using the same data source as you and I’m fine with the 5 days.

You can make a variable for each day and an automation pastes/moves the values to the right variable at 0:00.

Next year I’ll get a weather station :upside_down_face:

Awesome, I believe I am too.

I’m not sure what you mean here, is there any chance of when you get some free time showing your setup of this. (Are you saying make 31 blank variables that are written from day 5 essentially?); I think I would be very happy if you could sling some code at me.

I’m trying my best not to. I think I will abandon ship if I can’t get it digitally somehow. Rain data seems like a very difficult thing to get systematically within HA without paying for it and even then I can’t find any prewritten code/ sensor for it.

Thank you for jumping into this thread. It’s nice to know someone that has more capabilities than me has already went down this path for better or for worse. Thank you Florian!!

EDIT: I think you and @vingerha are leading me down the same path (but I’m not 100% sure). Is yours tied into your statistics also as he suggest? I’m really liking his thoughts/ layout.

Completely agree with you. I would be ok with the 5 day 24 hour period source.

I follow what you are saying and agree with the way you think I should move forward. This is actually exactly what I was hoping could be done. The only problem is, I don’t know how to do it.

I see. Could you walk me along on the steps to achieve your idea. So in my attributes, Day 0 is the 24 hour period starting at this exact time (or the time of the last sensor update) to a period of 24 hours in the past and this concept goes up until Day 4 (so 0-4 for 5 days). I guess you would take day 5 and write it to the statistics you are speaking of and then do this every 24 hours for day 5 at the same exact time each day?? Sorry, just speaking out loud, again, I just don’t know how to actually do it but I feel like that is the concept you are thinking of and I like it.

Also @vingerha , I don’t know if you would even need it or not. But the repo I am using, that is attaching to the source data, is here: https://github.com/petergridge/openweathermaphistory

ok… I believe I can help but I am out till next week so maybe someone else picks up…else you have to be patient :slight_smile:

Beggars can’t be choosers :slight_smile: . I am more than happy to be patient. Thank you for giving me some guidance and being willing to help. It will be a good learning experience for me also. I think the whole process could be useful for me in the future.

@FPro
I have one additional question that I just now noticed. It is related to the screenshot below. And the documentation for the integration we are both using. My sensor attributes (coming from the integration) show Day 0 rain through Day 5 rain for a total of 6 days. The documentation says it should only be day 0- day 4. What’s going on there? Have you been able to determine what is the proper 5 days to be looking at for rain (Days 0-4 or Days 1-5)----> This seems like a mistake on the development side but maybe something strange has happened when I brought the integration into my HA instance and was curious if you noticed that and had gotten to the bottom of it. The min/ max temp seems to have worked properly (i.e. Day 0- Day 4)

A little more information on the OpenWeatheMapHistory design.

  1. the API call supports up to 5 days of data the default is 4 days if no option is configured. Data is returned based on UTC time so the day is out of sync with by the time zone offset.
  2. The OpenWeatherMap API is called every 30 minutes so it uses a relatively small number of free calls, it was my requirement that it could coexist with the standard weather calls
  3. ‘days’ are a moving 24hrs with the rainfall/min max temp aging out into previous periods until it disappears in the 5th day. The API call returns a based on UTC time and it was difficult ( I gave up, my brain was to small for the problem :slight_smile: ) to determine the day based on time zone
  4. My use case was to limit the watering time based on history so the rolling 24hrs made more sense for me. As a result the 5th day is not a complete 24 hrs depending on UTC and the time zone.

I hope this helps answer some of the questions raised here

While I’m here I will add a shameless plug for my irrigation integration though

In relation to obtaining a history of your weather data, you can try this method.

Capture the rainfall for each day over an extended period by creating a template sensor that updates each night from this integration.

Once you have sufficient history you can use the History Stats - Home Assistant functionality to return the data for varying periods e.g. 7 days, 30 days etc.

   template:
        - trigger:
          - platform: time_pattern
            # This will update every night
            hours: 0
            minutes: 0 
          sensor:
          - name: "Daily Max Temp"
            unit_of_measurement: "°C"
            state: "{{ state_attr('sensor.rainfactor', 'day_0_max') }}"
          - name: "Daily Min Temp"
            unit_of_measurement: "°C"
            state: "{{ state_attr('sensor.rainfactor', 'day_0_min') }}"
          - name: "Daily Rainfall"
            unit_of_measurement: "mm"
            state: "{{ state_attr('sensor.rainfactor', 'day_0_rain') }}"

Argument for weather station: if you want watering input for your garden, you better get your local garden rain values. I have a netatmo rain meter and i did compare the values with online data, it’s way more accurate, even though in NL i can choose specifc meter stations from national local system, own sensor measurement cant be beaten.

My next steps to calculate watering needs is still a challenge. i have a pump to water and have no clue yet how much water it puts per period. There are several watering integrations helpers, but havent been able to leverage them

I don’t have a setup. As I said I’m fine with the values that are provided by Peter’s integration.
There more simple solution would probably be the one in Peter’s last post.

Ahh, I follow you. No problem. Thank you for your response. I will take a look at Peter’s last post.

Completely agree with you. Oh, the cheapness is strong with this one right now though. One day probably.

Hmmm, that is my next step. Identical to yours, if I come up with a solution, I will post it here.

@petergridge

Thank you so much for this. I’m so new to home assistant that I would have never figured this out. My “wants” outweight my “abilities” currently but hopefully they will catch up soon.

So these sensors will update every night and everytime they update the are stored in the background of home assistant. Then using the History Stats platform I can essentially use those in mass. This is great. Thank you @petergridge

Thank you for this because I didn’t know this either. Using the method you show in the next post, is there a way to get things to look proper timewise within home assistant. So for instance, I am in the Eastern Time Zone of US. Do I need to do anything to make the data line up with the proper time? So if I run an automation at midnight to save to the sensors. That will actually be 4 am Time Eastern Standard Time. (I don’t think this is an issue honestly but would like a little more info of what problem it could cause)

This is great.

So my integration shows day_0_rain, day_1_rain, day_2_rain, day_3_rain, day_4_rain, day_5_rain. Which is 5+days. So to make sure I understand. If the sensors refresh at 10:00 AM EST (2:00 PM UTC) on 6/23/2022, Day_0_rain will be valid for 10:00 AM EST(2:00 PM) UTC on 6/23/2022 until 10:00 AM EST(2:00 PM) UTC on 6/22/2022? Am I correct in this statement? In this instance, this will be the case for attributes day_0_rain, day_1_rain, day_2_rain, day_3_rain so this is 4 days of 24 hour rain, what would day_4_rain and day_5_rain look like for this example? I apoligize, I think the engineer is coming out of me. Thank you for helping me make sure I understand this fully.

The above is probably terribly written and not even understandable, I guess what I’m trying to get at is if you get time, would you give me an example of what these 6 attributes could look like at a random sensor update time.

And in your next post (template code). Do I put that in the packages folder? I guess what I’m wandering is how do I use that in an automation to tell it to save the data to the sensor. And if I put it in an automation for a 12 am EST time (4 am UTC). My day 0 will be 4am of the current day to 4 am of the previous day?

Thank you for clarifying this. I am very appreciative of the time you have spent.

Yeah, this is perfectly fine. And I follow you high level wise.

You’ve helped me more already than I could’ve ever helped myself haha.

I love it.