Hardware:
RB-SRAIN01 Solar Rain Sensor
QT06_2 Water irrigation valve
Problem description:
I want to sample data points for rain intensity every 5 minutes during the day.
If there is more than 10 datapoints with heavy rain since last irrigation, then I do not want to turn on the irrigation valve at the evening.
If there is more than 20 datapoints with moderate rain since last irrigation, then I do not want to turn on the irrigation valve at the evening.
If there is more than 30 datapoints with rain at all since last irrigation, then I do not want to turn on the irrigation valve at the evening.
Otherwise, turn on irrigation for half an hour at 18:00 in the evening.
I have defined the different rain levels through a templated helper sensor:
template:
- sensor:
- name: "Rain Rate"
state: >
{% set intensity = states('sensor.tuya_rain_sensor_rb_srain01_rain_intensity') | int %}
{% if intensity < 10 %}
No Rain
{% elif intensity <= 2000 %}
Light Rain
{% elif intensity <= 2600 %}
Moderate Rain
{% else %}
Heavy Rain
{% endif %}
The part with choosing when to start or not to start irrigation I have pretty much under control.
But I struggle with how to store counters which increase the value by one when there is some type of rain, and how to reset it at 18:30.
I reckon it will be something like this:
if “Heavy Rain” then ++Heavy_Rain_Counter;
if “Moderate Rain” then ++Moderate_Rain_Counter;
if (“Heavy Rain” or “Moderate Rain” or “Light Rain”) then ++Rain_Counter;
Is the solution a timed inject node which fetch “Rain Rate”, and goes to a switch node, which stores it to a global value?
(How do I save the global value so that it does not go away in case of a reboot, or a Node Red restart?)
Any hints, tips, tricks, pointers will be much appreciated.