Rain for last x days

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?

Because through the day when it is raining the total rain value keeps changing. Lets say it goes 1, 2, 3. The statistics TOTAL which is what I am interested in would be 6 (3+2+1 with a count of 3) when I actually want it to be 3. So I wait until just before midnight, which is when my weather station rain fall amount resets, and update input_number.rain_today_holder which then causes a single change to be recorded by the statistics sensor. I am thus attempting to have the statistics sensor only get one value per day and have a max days of 4 thus giving me total of last four days.

If there is a better way to do this I am all ears! :slight_smile:

There’s a max_value attribute of the statistics sensor that will show you the total rainfall for the sample period. The only issue is that the statistics sensor will give you stats for the last 4 days before now, not calendar days (i.e.if it is 3pm now the stats will extend to 3pm four days ago). No it wont. Because the sensor resets at midnight.

So your way is best.

The statisitics sensor updates whenever the monitored entity updates. Unfortunately that includes restarts.

I tried a bunch of ways to get this working, and ultimately i found the best way was to write the data to a database (mysql) outside of HA, and then using an sql sensor present the data to HA.

Originally i rolled my own code to monitor the MQTT topics coming out of weewx, but I have since moved it to a NodeRed flow.

Means the database is always up to date, data persists across reboots etc.

OK thanks. I will just have to put up with it then, As my system matures I am restarting less and I just this minute read how to get the advanced options for reloading without restarting so that will help!

Thanks. I am using MariaDb as part of Home Assistant so might be able to use that if my current approach remains problematic.

I think this, when developed, should be called the Eeyore sensor :slight_smile:

This is how I am attempting to do it. I’m only really interested if it rained heavily the day before, so I just have an input Boolean in Home Assistant ( automations/helpers/add helper/toggle) for yesterday’s rain, and one for today.

It checks just before midnight to see if it’s been raining that day, and again in the morning just before the irrigation comes on.

EdIT: there was a flaw in my logic in the deleted post, but this seems to work well.

This is some code from my own project which calculates a weighted total for rain and a 5 day moving temperature average. From here it determines a percentage increase or decrease for the irrigation time. Uses data from wunderground.com which is from my own PWS, pushed and retrieved by the wunderground integration. However, have since moved on to a new PWS which can push to my own NAS. Here it feeds a mysql db and with the sql integration creates the equivalent sensors in HA.