orange
(Calvin)
December 8, 2019, 11:30am
1
Hi All,
I got a https://www.banggood.com/Misol-WH-SP-RG-1PC-Spare-Part-For-Weather-Station-For-Rain-Meter-Measure-Rain-Volume-Rain-Gauge-p-1440220.html tipping rain gauge.
Connected it to a wemos d1 mini.
Each time the gauge tips, I get a ‘Rained’ on the /sensor/rainswitch/ mqtt topic.
I pick that up in homeassistant with
sensor:
- platform: mqtt
name: "rain_guage"
state_topic: "sensor/rainswitch"
icon: mdi:weather-rainy
value_template: "{{ 0.3537 | float }}"
(And try and turn it from a string Rained
to mm’s per tip aka value_template: "{{ 0.3537 | float }}"
.
And then I try and get some stats per hour on that:
- platform: statistics
name: mm_hour
entity_id: sensor.rain_guage
sampling_size: 3600
And then I throw those two into lovelace like:
cards:
- platform: statistics
name: mm_hour
entity_id: sensor.rain_guage
sampling_size: 3600 - platform: statistics
And I’m not getting what I want:
instead of a graph…
Any pointers would be appreciated.
tom_l
December 8, 2019, 11:33am
2
You need to add a unit of measurement to your sensor to get a line graph. Also you need to adjust your value template to this:
sensor:
- platform: mqtt
name: "rain_guage"
state_topic: "sensor/rainswitch"
icon: mdi:weather-rainy
value_template: "{{ value / 0.3537 }}"
unit_of_measurement: "mm"
orange
(Calvin)
December 8, 2019, 11:39am
3
Thanks! Certainly better:
Now let me go and pour some rain into it and see how that goes…
tom_l
December 8, 2019, 12:14pm
4
Actually the template is not correct I just read the bit about “rained” being the message. Try this:
value_template: >
{% if value == 'Rained' %}
{{ states('sensor.rain_gauge')|float + 0.3537 }}
{% else %}
{{ states('sensor.rain_gauge')|float }}
{% endif %}
Though I suspect this will not work either. This will only work if your di mini sends something other than ‘Rained’ after the ‘Rained’ message.
It would be a lot better if your d1 mini sent the number of bucket tips as the message rather than ‘Rained’. Then the template is just:
value_template: "{{ value * 0.3537 }}"
If you want a daily rain amount, use this sensor in the utility meter .
orange
(Calvin)
December 8, 2019, 12:24pm
5
Yup - "{{ value * 0.3537 }}"
throws TypeError: unsupported operand type(s) for /: 'str' and 'float'
The second one seems to be working - going to recompile the d1 mini, cause I like keeping it simple and will report back…
orange
(Calvin)
December 19, 2019, 1:00pm
6
Right - So I recompiled the wemos firmware (shout if anyone wants it) to return a number, instead of a string - so now my config looks like:
- platform: mqtt
name: "rain_guage"
state_topic: "sensor/rainswitch"
icon: mdi:weather-rainy
value_template: "{{ float(value) * 0.3537 }}"
unit_of_measurement: 'mm'
Now - the problem is, the wemos only sends a 1 each time the bucket tips - I don’t get it to add up over time or anything.
Anyway - then I add
utility_meter:
rain_daily:
source: sensor.rain_guage
cycle: daily
rain_monthly:
source: sensor.rain_guage
cycle: monthly
rain_weekly:
source: sensor.rain_guage
cycle: weekly
Now we wait a bit to see if things add up over time
phdelodder
(Philippe Delodder)
May 6, 2020, 7:22am
7
Could you share your code? I’m interested in making it myself.
Any chance you would share the firmware? I would love to take a crack at making one…
devzwf
(ZwF)
June 12, 2020, 4:19pm
9
Would be awesome if you cna share the D1mini code and how you hooked the misol to the mini
davegravy
(David Grant)
June 28, 2020, 8:00pm
10
Also interested in details on the hardware and firmware integration
SpikeyGG
(Greg G.)
October 12, 2020, 2:04pm
11
orange:
Now - the problem is, the wemos only sends a 1 each time the bucket tips - I don’t get it to add up over time or anything.
Anyway - then I add
Copy to clipboard
utility_meter:
rain_daily:
source: sensor.rain_guage
cycle: daily
rain_monthly:
source: sensor.rain_guage
cycle: monthly
rain_weekly:
source: sensor.rain_guage
cycle: weekly
Now we wait a bit to see if things add up over time
I’m very interested if this is working for you. I’ve set up a weather station a few months back. We finally had some rain yesterday and I got to see the rain gauge in action. Unfortunately, it’s not reporting what I was hoping.
The code (for ESPHome) looks like this:
time:
- platform: homeassistant
on_time:
- seconds: 0
minutes: 0
hours: /1
then:
- sensor.integration.reset: rainfall_per_hour
- platform: homeassistant
on_time:
- seconds: 0
minutes: 0
hours: 0
then:
- sensor.integration.reset: rainfall_per_day
sensor:
- platform: pulse_counter
pin:
number: D6
mode: INPUT_PULLUP
unit_of_measurement: 'in'
name: 'Rainfall Per Minute'
icon: 'mdi:weather-rainy'
id: rainfall_per_minute
count_mode:
rising_edge: DISABLE
falling_edge: INCREMENT
internal_filter: 50us
update_interval: 60s
filters:
- multiply: 0.011
accuracy_decimals: 3
- platform: integration
name: "Rainfall Per Hour"
id: rainfall_per_hour
time_unit: h
unit_of_measurement: 'in'
sensor: rainfall_per_minute
accuracy_decimals: 3
- platform: integration
name: "Rainfall Per Day"
id: rainfall_per_day
time_unit: d
unit_of_measurement: 'in'
sensor: rainfall_per_minute
accuracy_decimals: 3
Charts look like this:
At first glance, it appears to be working but then if you look at the scales, something is wrong. The daily accumulation for yesterday only reached 0.4" while the rainfall per minute reached nearly 2.9" at some point. Anyway, I noticed that you’re using the utility_meter
integrator. I might try that and see if it’s more like what I’d expect.
I’m sort of assuming that there’s a wiring or signaling problem because it’s very hard to believe that we got 2.9" in one minute (263 beats of the tip in one minute) but I’d like the math in ESPHome to line up at least for the accumulation/integration.
Thanks,
-Greg
orange
(Calvin)
October 12, 2020, 7:16pm
12
Right - I see what there’s been some interest here…
What I’ve now settled on is as follows - On the wemos d1 mini, I switched from my custom written stuff to ESPHome. The ESPHome Yaml is:
esphome:
name: misol_rainguage
platform: ESP8266
board: d1_mini
wifi:
ssid: "SSID"
password: "PW"
use_address: "IP"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Rainguage Fallback Hotspot"
password: "PW"
captive_portal:
# Enable logging
logger:
# Enable Home Assistant API
api:
password: "PW"
ota:
password: "PW"
sensor:
- platform: pulse_counter
pin:
number: D3
mode: INPUT_PULLUP
inverted: True
internal_filter: 6us
unit_of_measurement: "mm"
name: 'Rainfall'
accuracy_decimals: 3
filters:
- multiply: 0.367
- debounce: 1s
The “Internal Filter” combined with the “debounce” seems to mean my measurement is correct (i.e. its only reading each switch event).
Naturally - you’ll have to add the ESPHome stuff to Home Assistant as well.
In my configuration.yaml
I put:
utility_meter:
rain_daily:
source: sensor.rainfall
cycle: daily
rain_weekly:
source: sensor.rainfall
cycle: weekly
rain_monthly:
source: sensor.rainfall
cycle: monthly
rain_yearly:
source: sensor.rainfall
cycle: yearly
Then in lovelace:
type: entities
entities:
- entity: sensor.rainfall
- entity: sensor.rain_daily
- entity: sensor.rain_weekly
- entity: sensor.rain_monthly
- entity: sensor.rain_yearly
Gives something like this.
Naturally - you can add your various graphs etc. as you wish.
Much easier and simpler than what I was doing - hacking my own c code…
orange
(Calvin)
October 12, 2020, 8:22pm
13
Yeah - first my gauge wasn’t reading much @ 13us (the default) - so I moved it down to 6us on the ‘internal_filter’ and upped the ‘debounce’ to 1s - seems to be ok now …
SpikeyGG
(Greg G.)
October 14, 2020, 2:03am
14
I’ll try out the debounce and see if that helps… now I just need some more rain.
That may solve the 2.9" measurement but still doesn’t address why the per-day accumulation is so much less than I’d expect.
orange
(Calvin)
October 14, 2020, 8:20am
15
SpikeyGG:
I’ll try out the debounce and see if that helps… now I just need some more rain.
That may solve the 2.9" measurement but still doesn’t address why the per-day accumulation is so much less than I’d expect.
Yeah - I can see that you’re doing your accumulation on the measuring device.
My approach is to get raw data from the device and let the accumulation be done via HA.
You could just simply add the “utility_meter” stuff I’ve done in HA on your “rainfall_per_minute” sensor and see how that works - compare it to your device figures and if it gives you better results, then away you go…
I agree, I managed to get this working by just logging the tips of the rain gauge to influxdb, and having a cron job poll the influxdb and log the last 24 hours to a different influxdb value
! crontab
*/5 * * * * perl /home/radmin/homescripts/rain_gauge_sum.pl
! rain_gauge_sum.pl
`
#!/usr/bin/perl
our $key_name=“RainGauge”;
my $value=&GetCurrentSum;
&PostValue($value);
sub GetCurrentSum
{
@output=influx -format=csv -execute 'SELECT sum(*) FROM "RainGauge" where time > now() - 24h' -database=udp_loggers
;
foreach (@output )
{
chomp();
($key,$time_val,$value) = split (/,/);
if ($key eq $key_name) { return $value;
}
}
die “key not found $key_name\n”;
}
sub PostValue
{ my $value_post=shift;
print influx -execute 'INSERT RainGaugeSum,name=value value=$value_post' -database=udp_loggers
;
}
!
`
fyi, the graph loses accuracy as I had 2 days of power outage on 10/29, hence the slope…
Future enhancements could be to calibrate to estimate inches of rainfall, instead of just tips of the rain bucket…
SpikeyGG
(Greg G.)
March 19, 2021, 7:38pm
18
I wanted to mention that I got this to work (completely from inside ESPHome):
ESPHome creates two integration sensors one for each accumulation.
time:
- platform: homeassistant
timezone: America/Somewhere
on_time:
- seconds: 0
minutes: 0
hours: /1
then:
- sensor.integration.reset: rainfall_per_hour
- seconds: 0
minutes: 0
hours: 0
then:
- sensor.integration.reset: rainfall_per_day
sensor:
- platform: pulse_counter
pin:
number: D6
mode: INPUT_PULLUP
unit_of_measurement: 'in'
name: 'Rainfall Per Minute'
icon: 'mdi:weather-rainy'
id: rainfall_per_minute
count_mode:
rising_edge: DISABLE
falling_edge: INCREMENT
internal_filter: 50us
update_interval: 60s
filters:
- multiply: 0.011
- debounce: 400ms
accuracy_decimals: 3
- platform: integration
name: "Rainfall Per Hour"
id: rainfall_per_hour
time_unit: min
unit_of_measurement: 'in'
sensor: rainfall_per_minute
accuracy_decimals: 3
- platform: integration
name: "Rainfall Per Day"
id: rainfall_per_day
time_unit: min
unit_of_measurement: 'in'
sensor: rainfall_per_minute
accuracy_decimals: 3
It resets in accordance with the time thresholds (on the minute, on the hour, on the day, on the month) but I really want to display a running average in the chart and I’m having a hard time wrapping my head around how to do that (maybe I shouldn’t use the integration sensor since I have to reset it manually?) I wonder if a template sensor (updated every 60s) with a sliding_window_moving_average is more what I want… I’ll have to play with that a little.
Hi,
I have read the course but somehow I am not quite able to get by, someone may be able to help me a little.
I also use the rain sensor from Misol, which I connected to a Wemo D1 mini with Tasmota.
I transmit the counting pulse via MQTT as a switch (end position = off, movement is ON; 1 off-on-off is a pulse)
However, I cannot set up an evaluation in mm / qm according to time intervals.
I created a rain sensor as follows.
sensor rain:
platform: mqtt
state_topic: "stat/Wetterstation2/POWER"
name: "Regen"
But the conversion and expanded display somehow doesn’t work
best regards
Gerald
orange
(Calvin)
March 26, 2021, 7:38am
20
Yeah - not sure how to count mqtt events.
Using esphome’s pulse counter worked for me.
In fact, I’ve moved most of my devices off tasmota to esphome - it is way easier to manage for me.