☔ DIY Zigbee rain gauge

This line in the daily rain sensor will probably solve these issues

availability: "{{ (states('sensor.rainsensor_flips') not in ('unknown', 'unavailable')) }}"

Personally I’ve never had the issue

Yes that will do the trick i’m sure, and it will save me from creating a separate inverted sensor.

That availability line doesn’t work anymore in new HA btw, it’s availability_template: now. I noticed some other stuff in the code as well that doesn’t work anymore (like state vs value_template).

Also, i noticed your hourly sensor that you put in binary_sensors.yaml, i’m using the utility platform for that. Doesn’t that work the same way?

It’s actually the new way of defining template sensors. I read somewhere that the other way will be deprecated in 2022.9.

Rain intensity aka mm/h will calculate the time between two tips and calculate how many mm will fall if it would keep raining that fast.
The utility you are talking about is only counting how many rain fell in the current hour. This is what the mm/h sensor looks like in a graph. It peaked 128mm/h, I think it was the most rain I had since I installed the sensor (1,5 years).

30mm of rain in 45 minutes

1 Like

Ok i must have done something wrong then, i need to read that page fully. I do see both availability and av availability_template, but seemingly applying to different sections.

Ah ok, so rain intensity is like a forecast/trend, and the utility is just the total amount of rain that fell in the hour.

Stupid question, where do you add the following code?

binary_sensor:
  - platform: trend
    sensors:
      rainfall_trend:
        entity_id: sensor.rainfall_today
        max_samples: 2

template:
  - sensor:
      - name: "Rain intensity"
        unit_of_measurement: 'mm/h'
        state_class: measurement
        unique_id: rainfall_per_hour
        state: >-
          {% set rain_hour = ((state_attr('binary_sensor.rainfall_trend', 'gradient') | float(0)) * 3600) | round(1, 'floor') %}
          {% if rain_hour >= 0 %}
            {{ rain_hour }}
          {% else %}
            {{ 0 }}
          {% endif %}

I have a separate binary_sensor.yaml file, the first part can go in there of course. What about the part after that? Can i put that in there as well? I tried doing that but it didn’t like it :frowning:

What does your configuration.yaml looks like? You can probably put it in there, or create a file named template.yaml and include it like it’s done with binary_sensor.yaml. Then put it in there.

See Splitting up the configuration - Home Assistant

ok. Received my last item yesterday and started the project this morning. Done by noon. Waiting for rain now.

I would like to be notify the first sign of rain. Anyone knows how to approach this?

Use this as trigger with the current state in there

platform: state
entity_id:
  - sensor.rainfall_today
from: '0'

I added it like this to my binary_sensors.yaml:

# Rainfall trend forecast amount of mm/h
  - platform: trend
    sensors:
      garden_rain_sensor_1_rainfall_trend:
        entity_id: sensor.garden_rain_sensor_1_rainfall_today
        max_samples: 2
  
 # Rainfall intensity      
  - sensor:
      - name: "Garden Rain Sensor 1 Rain intensity"
        unit_of_measurement: 'mm/h'
        state_class: measurement
        unique_id: garden_rain_sensor_1_rainfall_per_hour
        state: >-
          {% set rain_hour = ((state_attr('binary_sensor.garden_rain_sensor_1_rainfall_trend', 'gradient') | float(0)) * 3600) | round(1, 'floor') %}
          {% if rain_hour >= 0 %}
            {{ rain_hour }}
          {% else %}
            {{ 0 }}
          {% endif %}

But i get:

Configuration invalid!
 Invalid config for [binary_sensor]: required key not provided @ data['platform']. Got None. (See /config/configuration.yaml, line 55). 

When i check my configuration.

What is on line 55? The error is about a binary_sensor but you haven’t shown code for one.

The rain intensity sensor does not belong in the binary_sensor.yaml.

Read the link I sent you above about splitting the configuration :slight_smile:

I put it in template.yaml and include it as template: !include template.yaml from the configuration.yaml, that seems to pass a configuration check.

I guess i just don’t understand the difference between your yaml code

# Rainfall intensity      
  template:
  - sensor:
      - name: "Garden Rain Sensor 1 Rain intensity"
        unit_of_measurement: 'mm/h'
        state_class: measurement
        unique_id: garden_rain_sensor_1_rainfall_per_hour
        state: >-
          {% set rain_hour = ((state_attr('binary_sensor.garden_rain_sensor_1_rainfall_trend', 'gradient') | float(0)) * 3600) | round(1, 'floor') %}
          {% if rain_hour >= 0 %}
            {{ rain_hour }}
          {% else %}
            {{ 0 }}
          {% endif %}

And for example, this (which is in binary_sensors.yaml ):

# Washing machine, dryer and dishwasher states
  - platform: template
    sensors:
      utility_room_washing_machine_1_current:
        friendly_name: "Utility Room Washing Machine Status"
        delay_on: "00:05:00"
        value_template: "{{ states('sensor.utility_room_washing_machine_1_current')|float(0) > 6 }}"
        device_class: running

I guess i’m confused between a real template that goes in a template.yaml file and something that uses the platform template (which also uses sensors rather then sensor in it’s yaml code).

The difference is that the way the rainfall intensity is written, is the new way to define a template sensor. You could rewrite your old template sensor into the following:

# Rainfall intensity      
  template:
  - sensor: 
      - name: "Garden Rain Sensor 1 Rain intensity" #this is a template sensor
        unit_of_measurement: 'mm/h'
        state_class: measurement
        unique_id: garden_rain_sensor_1_rainfall_per_hour
        state: >-
          {% set rain_hour = ((state_attr('binary_sensor.garden_rain_sensor_1_rainfall_trend', 'gradient') | float(0)) * 3600) | round(1, 'floor') %}
          {% if rain_hour >= 0 %}
            {{ rain_hour }}
          {% else %}
            {{ 0 }}
          {% endif %}
  - binary_sensor: 
    - name: "Utility Room Washing Machine Status" # This is a template binary_sensor
      unique_id: utility_room_washing_machine_1_current
      delay_on: "00:05:00"
      state: "{{ states('sensor.utility_room_washing_machine_1_current')|float(0) > 6 }}"
      device_class: running

Ah ok, i think i get it. So in your code both sensor and binary_sensor fall under template:
I can either put this code into configuration.yaml or include it in a template: !include template.yaml and then leave out the template: part.

Can i mix and match? If i did want to include the new rain intensity template sensor style within say, binary_sensors.yaml (not saying i’m going to, just for my understanding), would that work and if it did, i probably would have to preface it with template: ?

I think i will probably put everything in a template.yaml anyway.
Thanks for your help.

Just use the new format :slight_smile:

1 Like

Im confused. In original post, the mm/pulse is .30303

But if it tipped 6 times when you put 10mL worth of water into it then 6 tips x .30303 would be 1.8 mL

Shouldent it equal 10mL?

I know I am wrong, I just need someone to explain it to me.

Additionally, what am I doing wrong in my sensor.yaml? It wont let me restart my HA with the added stuff. Im a node red guy, so this yaml stuff is really my Achilles heel.

- platform: template
  sensors:
     washer_door_lock:
       friendly_name: "Washer Door Lock"
       value_template: "{{ state_attr('sensor.washer','door_lock') }}"
 
     washer_time_display:
       friendly_name: "Washer Time Display"
       value_template: >
         {% if is_state('sensor.washer_run_state', '-') %}
         {% elif is_state('sensor.washer_run_state', 'Standby') %}
           -:--
         {% else %}
           {{ state_attr('sensor.washer', 'remain_time') }}
         {% endif %}
         
     dryer_time_display:
       friendly_name: "Dryer Time Display"
       value_template: >
          {% if is_state('sensor.dryer_run_state', '-') %}
          {% elif is_state('sensor.dryer_run_state', 'Standby') %}
            -:--
          {% else %}
            {{ state_attr('sensor.dryer', 'remain_time') }}
          {% endif %}
          
- platform: time_date
  display_options:
  - 'date_time'
  - 'date'

#CANT RESTART WITH STUFF BELOW HERE ADDED
- platform: history_stats
  name: Rainsensor flips 
  entity_id: binary_sensor.rain_sensor_tips
  state: 'off'
  type: count
  start: '{{ now().replace(hour=0, minute=0, second=0) }}'
  end: '{{ now() }}'
  

- sensor:
      - name: Rainfall today
        unit_of_measurement: mm
        state_class: total_increasing
        unique_id: rainfall_today
        state: >-
          {% set count = states('sensor.rainsensor_flips') | int(0) %}
          {% set mm = count * 0.30303 %}
          {% if count >= 0 %}
            {{ mm|round(1, 'floor') }}
          {% endif %}
        # If you have issues with the history sensor doubling after restarting HA, add the line below (@BigG)
        availability: "{{ (states('sensor.rainsensor_flips') not in ('unknown', 'unavailable')) }}"

Simply said, the catch area is taken into account.

The sensor is written in the new template format, see the discussion above :slight_smile:

Is there a description in this thread how to properly attach and configure the gauge woth an D1 mini and ESPhome?

If not, can somebody who did it give me a hint?

Esp8266 setup