Rain for last x days

Hi everyone.

I have a WiFi connected weather station, with weewx up and running pushing data into HA. This is all working as expected.

One of the attributes it sends is dayRain – ie how much rain has fallen today. What i want to do is use this data, and work out how much rain has fallen over the last x days.

I feel like to do this i need to potentially use a combination of the historical statistics sensor to collate the data, and the normal statisics sensor to set a sample size, but i just cant quite work it out.

Surely someone has worked this out before ? There are a bunch of similar type questions on the forums, but no definitely answer (that i could find!)

Thanks,
Dan.

You should just need the statistics sensor. Set max_age to “x days” (assuming it is a constant). This will give you a total attribute for the last x days.
One trap to watch out for though is to make sure your sampling_size is set large enough to cover “x days”, otherwise the sensor will start dropping old values.

I think i missed the whole max_age thing! That makes sense.
Ive just tried it again and will keep an eye on it – not raining at the moment though!

THe issue ive been runnig into so far is the rain today value gets send in every data set, so every 2 minutes or so, not just once a day.

eg i get 2mm of rain at 2am, but nothing more. That 2mm gets sent every 2 mins all day, not just when it happened.

Ah. That could be a problem. It’s going to add all those up.

What time does it reset? Midnight or 9am?

We get official “rain since 9am” forecast reports for some historical reason.

The only way around it that I can think of is to make a template sensor that updates from your dayRain sensor just before it resets every day. Then track the template sensor with the statistics sensor for x days total.

Thats not a bad solution. I guess i will need to play!
From what i can see it resets at 00:00 - but ive only had the data feeding into HA for a couple of days. I originally bought a new WeatherStation with the idea of grabbing data out via their API, but by the time it arrived, the API wasnt available any more!

One of those might be me :slight_smile:

I am interested in this from a slightly different angle though as I don’t have a weather station. I have been toying with the possibility of getting one though so I am interested in what you have.

I currently try to use rainfall as reported by DarkSky in my irrigation system to adjust watering times (without a great deal of success mainly because interpreting the data is a minefield).

Another solution for watering is the Miflora moisture sensor. Esphomeyaml can connect them to HA. You’d still have to look at the forecast for future rain but soil moisture is a better indicator of watering required than past rain. As wind, temperature and soil drainage also play a part.

Ive locked at mi flora before – the issue is BT range – the spots i would want to put them are just a bit far away :frowning: i guess for the cost its potentially worth a go!

The tracking of rain wasnt strictly JUST due to watering, its more a want than a need.

That’s the beauty of using esphomeyaml. They connect to the miflora by BT but to HA by wifi, which has a much greater range. If you use an esp32 you can put them to sleep for most of the time and run the whole thing off a 3W solar panel and an 18650 battery.

Yeha its worth looking at … i dont really have anywhere to put the ESP32 either!

Ive actually got some credit with Mi Global Store due to some order stuff ups, might be time to place an order!

Back to the rain tracking – one of the attributes im getting from the weather station is rain last 24 hours – is there a way to make the statistics sensor only sample the data once every 24 hours ??

So i actually tackled this from a different perspective.

Im grabbing the data out and saving it by date, outside of HA. I am then pushing the sum of the most recent value for each distinct date, for the last x days, into HA via mqtt as a single sensor.

It was just easier that way. Ive already got a raspbian Pi sitting around doing not much anyway.

Its using PHP and existing mqtt libraries, and happy to share if it helps anyway
It doesnt even need a web server running, as its all subscription and publish to mqtt based, just php and an sql server (i used mysql)

Thanks,
Dan.

So i bit the bullet and got a couple.

Ive got it all working … as expected the main issue was BT range. I have to have it out in the garden for it to pick up the Mifloras.

Can you give me any more info RE your solar/battery setup for it ?

I tried looking for ways to boost the BT range, but couldnt find anything concrete.

Please re-read what I wrote. You need a BT connection to a NodeMCU-32S running ESPhome. The ESP does the talking to HA via wifi (much much greater range).

Hi.
Thats what ive got. a NodeMCU-32s running esphomeyaml, with the 2 sensors configured. It publishes data to MQTT via WiFi, and HA is picking that up.

What I said “Ive got it all working” thats what i meant. Re-reading it now, its not at all clear!

To get it to work, ive had to put the 32s out in the garden, running off a battery pack. I was hoping i would be able to put it on my patio where theres a powerpoint and its undercover, but it seems to only have a BT range of 1-2 metres, whereas using the Flower Care app its more like 6 or so.

Sorry, and thanks

Ah right sorry. I misunderstood.

I’m using the following to solar power my remote devices:

https://www.ebay.com.au/itm/5-TP4056-5V-1A-Micro-USB-18650-Lithium-Battery-Charge-Board-Protection-Module/183346055240?hash=item2ab046c848:g:u2EAAOSwvRlbWnE2:rk:1:pf:0

Don’t skimp on the solar panel. I tried a few cheap Chinese ebay panels before realising they all lie about the panel ratings. Panels sold as 5W gave no more than 200mW of usable power.

I also tried using a few 18650 cells I’d scavenged from solar garden lights. These were terrible. Fully charged they’d drop from 4.1V to 3.1V under load and the ESP would reset.

You don’t need protected 18650 cells if you use the TP4056 module with protection (it is available without - look carefully at the listing). The cells listed above I had left over from another project and are absolute overkill for this application (they can supply 10A, the ESP32 draws very short peaks of 700mA). You should only need one cell per ESP board - depending on how often your device wakes from sleep.

Solar panel, load and battery connections are all clearly marked on the TP4056 charge board.

EDIT: I also tried this MPTT charge module: https://www.sparkfun.com/products/12885 it’s not worth the price. Go with the TP4056 module .

I am still trying to get this working to my satisfaction. Currently I am trying to use the statistics sensor.

In configuration.yaml

  - platform: statistics
    name: Actual Rainfall Last 4 Days
    entity_id: input_number.rain_today_holder
    max_age:
      days: 4

input_number:
  rain_today_holder:
    name: "Rain Today Holder for 4 Day Tracking" 
    min: 0
    max: 500

But I found that it was coming up as unknown if the rain today was zero. So I added this automation:

- alias: Update rain today holder
  trigger:
    - platform: time
      at: "23:59:50"
  action:
    service: input_number.set_value
    entity_id: input_number.rain_today_holder
    data_template:
      value: >
        {% if states('sensor.wupws_preciptotal') | float > 0.0 %}
          {{ states('sensor.wupws_preciptotal') }}
        {% else %}
          {{ 0.1 }}
        {% endif %}

I am still trying to carefully watch this to make sure it is working as advertised. One problem I am still having is the statistics update on a restart. Is there any way to stop that? I just want it to update just prior to midnight as per my automation…?

The problem is that the statistics sensor has a default setting of 20 samples max. You are going to hit that cap well before 4 days. You should raise it to a much higher level. See: https://www.home-assistant.io/integrations/statistics/#sampling_size

A good value would be 1.5 x 4 days (in seconds) / average sensor update rate (in seconds).

You should then be able to use the precipitation sensor directly in the statistics sensor without having to use an input number and template sensor.

Actually it is OK because I have the statistics monitoring input.number_rain_today_holder which I only change once per day per the automation.

Can you help me understand why you are using that intermediary step?