thanks for that detailed explanation.
But this is a lil bit too much for me
can you (simple) explain, where I have to integrate the two codes from the first post?
I added the sensor to my home assistant and I get “open/closed” status…
Now I have to integrate the code, if I understand the proceed correctly?
The code has to be under the sensor:
line. If it’s not present, create it
thank you, now it works
Now I have to figure out, how I can implent this to node red to create a telegram message, if rain starts
okay, today I simulated rain with a watering can
I realized that I have an problem with my code, the “Regenfall heute” (rainfall today) doesn’t count…
#Regensensor
- platform: history_stats
name: Regenmesser
entity_id: binary_sensor.regensensor
state: 'off'
type: count
start: '{{ now().replace(hour=0, minute=0, second=0) }}'
end: '{{ now() }}'
- platform: template
sensors:
regenfall_heute:
friendly_name: Regenfall heute
unit_of_measurement: mm
value_template: >-
{% set count = states('binary_sensor.regensensor') | int %}
{% set mm_per_pulse = 0.30303 %}
{% set mm = count * mm_per_pulse %}
{{ mm|round(1, 'floor') }}
Can you tell me, which sensor I need to implement in 4th last row (current is binary_sensor.regensensor insert)?
Dont know why in the first post is there a second sensor and not the binary_sensor included…
Edit:
Got it!
have to set the sensor.regenmesser
Use this
- platform: template
sensors:
regenfall_heute:
friendly_name: Regenfall heute
unit_of_measurement: mm
value_template: >-
{% set count = states('sensor.regenmesser') | int %}
{% set mm_per_pulse = 0.30303 %}
{% set mm = count * mm_per_pulse %}
{{ mm|round(1, 'floor') }}
Your idea of inverted sensor works flawlessly. So simple and effective. Thanks for sharing !
I was a bit terse with my picture response but I have been very busy elsewhere, sorry.
So, I should add that it took a bit of trial and error to get the sensor in the right place because the reed switch lies horizontally. But is seems reliable. As you can see I added a small magnet to the pivot point and had to lift the sensor up a bit off the base. I used some magnetic tape I had lying around and stuck a couple of magnets on the bottom of the sensor. That way, not only could I lift it higher in small increments by adding extra magnets but I can also move it around to get it aligned properly and remove it easily when I need to change the battery.
In case it is useful, here is my config but it hasn’t rained since I installed it so can’t be 100% certain it is right but it seemed good in testing…
#===================
#=== Binary Sensors
#===================
binary_sensor:
- platform: mqtt
name: rain_gauge
state_topic: 433/rain_gauge
off_delay: 1
#============
#=== Sensors
#============
sensor:
#==================
#=== History Stats
#==================
# Today
- platform: history_stats
name: Rain Gauge Tips Today
entity_id: binary_sensor.rain_gauge
state: "on"
type: count
start: "{{ now().replace(hour=0, minute=0, second=0) }}"
end: "{{ now() }}"
# Yesterday
- platform: history_stats
name: Rain Gauge Tips Yesterday
entity_id: binary_sensor.rain_gauge
state: "on"
type: count
end: "{{ now().replace(hour=0, minute=0, second=0) }}"
duration:
hours: 24
Well, I think that this is going to have to be the next project! Awesome!
To recap for someone who’d want to start from scratch with these modifications, here’s my setup.
Feel free to suggest corrections or ameliorations !
configuration.yaml
recorder:
purge_keep_days: 30
auto_purge: false
include:
entities:
# this is the aqara door contact
- binary_sensor.rain_gauge
# special sensor to avoid hits at HA startup
- binary_sensor.rain_gauge_invert
# count of each gauge flip
- sensor.daily_gauge_flips
# history stats works well for daily rainfall
- sensor.daily_rain
# utility meter works better for hourly rainfall
- sensor.hourly_rain
binary_sensor:
- platform: template
sensors:
rain_gauge_invert:
value_template: >-
{{ is_state('binary_sensor.rain_gauge', 'off') }}
device_class: door
utility_meter:
hourly_rain:
source: sensor.daily_rain
cycle: hourly
sensors.yaml
- platform: history_stats
name: Daily Gauge Flips
entity_id: binary_sensor.rain_gauge_invert
state: 'on'
type: count
start: '{{ now().replace(hour=0, minute=0, second=0) }}'
end: '{{ now() }}'
- platform: template
sensors:
daily_rain:
unit_of_measurement: mm
value_template: >-
{% set count = states('sensor.daily_gauge_flips') | int %}
{% set mm_per_pulse = 0.30303 %}
{% set mm = count * mm_per_pulse %}
{{ mm|round(1, 'floor') }}
availability_template: >
{% if is_state("sensor.daily_gauge_flips", "unavailable") %}
false
{% else %}
true
{% endif %}
Well, actually this tweaking is not neccessary.
I’m my code is device_class: door
for the inverted sensor. That takes care of the states
(Hence it’s also a door class sensor we are invertedly duplicating)
forgot that bit… That explains it. Thanks I’ve corrected.
Are you sure it’s a sensor and not a binary sensor ? Because class door for sensor gives me an error…
edit: Alright, binary sensor it is. All works well and I’ve updated the code.
device_class are part of the binary sensor
Well yes, it is in my binary_sensors.yaml… I should’ve specified that…
All good now^^
Thanks again, those damn hits at startup where a deal breaker when monkeying around is causing a lot of reboots. Very happy with the result
How did the accuracy check go? Did you calibrate this yourself using OP’s method or did you just use his numbers?
My calibrations came to the same as OP,s numbers and compared to the other rain gauge it’s pretty accurate…
I built one of these today, however since I only have Z-Wave devices, I wanted to stick with that.
I cannibalized a HomeSeer door/window sensor and got it “working”
However, it is not working because it seems** as though the reed switch changes states too fast for the HomeSeer sensor to recognize it.
See below linked-video.
When the “seesaw” flips back and forth during periods of rain, it does so very quickly, as depicted in the first part of the video.
Any ideas or suggestions?
It might be obvious but have you tried repositioning the device? It took me a while to get the best location for mine and as you can see in my photo it is quite a bit off centre.