Trying to use the mini-graph-card for my home built rain sensor
It’s based on this project:
https://www.reddit.com/r/3Dprinting/comments/16azwxr/3d_printed_diy_zigbee_rain_sensor_based_on_aqara/
A dual tipping bucket monitored by a magnetic door contact that flips to 0 or 1 (or wet and dry in my code) (code for platform- and template sensors below)
If I summarize the number of flips for last day, it is 27, that corresponds to 14.2 mm of rain, so that looks to be correct
But - the hourly graph doesn’t give the same when I summarize it!
I had expected the last four hours to show sum up to the same as last 24h (as it has not been raining for a couple of days, so nothing from yesterday should be able to affect it.
# Regnsensor platform sensor rain/24h
- platform: history_stats
name: "Regn Contact Flips/Dry"
entity_id: binary_sensor.regn_contact
state: "off"
type: count
start: "{{ now() - timedelta(hours=24)}}"
end: "{{ now() }}"
- platform: history_stats
name: "Regn Contact Flips/Wet"
entity_id: binary_sensor.regn_contact
state: "on"
type: count
start: "{{ now() - timedelta(hours=24)}}"
end: "{{ now() }}"
#unavailable
- platform: history_stats
name: "Regn Contact Flips/unavailable"
entity_id: binary_sensor.regn_contact
state: "unavailable"
type: count
start: "{{ now() - timedelta(hours=24)}}"
end: "{{ now() }}"
# Regnsensor platform sensor rain/h
- platform: history_stats
name: "Regn Contact Flips/Dry_hour"
entity_id: binary_sensor.regn_contact
state: "off"
type: count
start: "{{ now() - timedelta(hours=1)}}"
end: "{{ now() }}"
- platform: history_stats
name: "Regn Contact Flips/Wet_hour"
entity_id: binary_sensor.regn_contact
state: "on"
type: count
start: "{{ now() - timedelta(hours=1)}}"
end: "{{ now() }}"
#unavailable
- platform: history_stats
name: "Regn Contact Flips/unavailable_hour"
entity_id: binary_sensor.regn_contact
state: "unavailable"
type: count
start: "{{ now() - timedelta(hours=1)}}"
end: "{{ now() }}"
template:
#Template Regnsensor rain/24h
- sensor:
- name: Rainfall [day]
state_class: measurement
unique_id: rainfall_day
unit_of_measurement: mm
icon: mdi:weather-pouring
state: >-
{% set count = (states('sensor.regn_contact_flips_dry') | int(0)) + (states('sensor.regn_contact_flips_wet') | int(0)) - (states('sensor.regn_contact_flips_unavailable') | int(0)) -1 %}
{% if count < 0 %}
{% set count = 0 %}
{% endif %}
{% set mm = count * 0.52615 %}
{% if count >= 0 %}
{{ mm|round(1, 'floor') }}
{% endif %}
#Template Regnsensor rain/h
- sensor:
- name: Rainfall [hour]
state_class: measurement
unique_id: rainfall_hour
unit_of_measurement: mm
icon: mdi:weather-pouring
state: >-
{% set count = (states('sensor.regn_contact_flips_dry_hour') | int(0)) + (states('sensor.regn_contact_flips_wet_hour') | int(0)) - (states('sensor.regn_contact_flips_unavailable_hour') | int(0)) -1 %}
{% if count < 0 %}
{% set count = 0 %}
{% endif %}
{% set mm = count * 0.52615 %}
{% if count >= 0 %}
{{ mm|round(1, 'floor') }}
{% endif %}
(the -1 for “set count” is because the sensor looks to present itself with status on every reboot and that looks to count as well)
The code for my lovelace card looks like this
square: false
type: grid
cards:
- type: custom:mini-graph-card
icon: mdi:weather-rainy
name: Regn/timme
aggregate_func: max
hours_to_show: 24
group_by: hour
show:
graph: bar
fill: true
icon: false
color_thresholds:
- value: 100
color: '#8a111e'
- value: 50
color: '#c7311c'
- value: 25
color: '#fc5a43'
- value: 10
color: '#fc8582'
- value: 5
color: '#fbab3e'
- value: 2
color: '#ebf438'
- value: 1
color: '#79cf3f'
- value: 0.5
color: '#24cbcc'
- value: 0.2
color: '#3296de'
- value: 0
color: '#373737'
entities:
- entity: sensor.rainfall_hour
state_adaptive_color: false
- type: custom:mini-graph-card
icon: mdi:weather-rainy
name: Regn/dygn
aggregate_func: avg
hours_to_show: 360
group_by: date
show:
graph: bar
fill: true
icon: false
color_thresholds:
- value: 100
color: '#8a111e'
- value: 50
color: '#c7311c'
- value: 25
color: '#fc5a43'
- value: 10
color: '#fc8582'
- value: 5
color: '#fbab3e'
- value: 2
color: '#ebf438'
- value: 1
color: '#79cf3f'
- value: 0.5
color: '#24cbcc'
- value: 0.2
color: '#3296de'
- value: 0
color: '#373737'
entities:
- entity: sensor.rainfall_day
state_adaptive_color: false
columns: 1
title: Regnmätare
What is it I don’t understand or have missunderstood?
Why doesn’t hours sum up to the same value as last 24h?
Edit/Add:
Today (day after) the 24h graph doesn’t make any sense to me…
Only 7.84 yesterday (showed above 15 when I went to bed around 23/11pm yesterday and 8.11 for today…while Rain/day shows as 1.5mm…!?
The hourly graph shows it has not been raining since 18/6pm yesterday…why does the daily grahp shows 8.11 for 12am-11.59pm today!?