This is a question about entity storage update frequency. Is there a way to send single entity data to HA at a longer interval between than the entity is generated by the ESP8266 yaml config
file? Sounds easy, just increase the update_interval. Unfortunately that will not work for this application. I need 1 second updates inside the yaml file as I am switching a water pump relay inside the yaml file.
I only need HA to display my data but I do not want the fille up my disk space with extraneoaus datapoints. Why do I need this?
I have an indoor hydrangea plant. I am watering this automatically with an ESP8266 and Home Assistant. Hydrangeas require soil humidity of roughly between 40 to 60%. To do this I have a
simple and very cheap two metal soil moisture sensor. This produces between 0 and 125mV which represents 0 and 100% soil moisture. I just soldered two wires to the back of the meter and connected this between GND and A0 on the ESP8266. The output from the meter is continuus and jumps around quite a bit. It displays on the meter as quite stable and this is due to
mechanical inertia in the meter construction. However I am left with a continuous stream of fast changing data coming in to my ESP8266.
I am usng sliding_window_moving_average: to smooth out the raw data and then lambda sends it to HA.
I need to turn the water pump on and off fairly quickly so I am doing this locally in the ESP8266 yaml file. It turns on a 42% humidity and off at 55%. It needs to run for about 10 - 15 seconds each time. I do not want too much water or, too little.
I did this in yaml for two reasons. 1). if the HA server goes down, the plant will still get watered. 2. To not send lots of useless data points to HA.
It is point 2. that is the subject here.
How can I get extenmely fast (1 sec) response within yaml but send only once every 5 minutes or so of smoothed (sliding_window_moving_average:) data to HA?
Any help here is welcome.
Thanks
My code is below.
switch:
- platform: gpio
pin: D2
id: water_pump
icon: mdi:water-pump
name: "Water Pump"
sensor: # Cheapo Soil Humidity Sensor
- platform: adc
pin: A0
id: indoor_hydrangea_humidity_percent
icon: mdi:water-percent
name: "Indoor Hydrangea Soil Moisture"
unit_of_measurement: "%"
accuracy_decimals: 1
# Adjust the sensor output to give meaningful % readings
filters:
- calibrate_linear:
- 0.00568 -> 0.0
- 0.02637 -> 40.0
# Average several readings
- sliding_window_moving_average:
window_size: 10
send_every: 5
# Send the output to HA
- lambda: return x;
# Turn the Pump relay on and off
on_value_range:
- above: 55.0 # Turn off at 68%
then:
- switch.turn_off: water_pump # Pump relay off
- below: 42.0 # Turn on at 54%
then:
- switch.turn_on: water_pump # Pump relay on
update_interval: 1s
In general you can use internal: true so that the entity isn’t reported to home assistant at all, and then you can create a template sensor using whatever update interval and filters you want.
Yes, that is another way to do the job. I kind of agree with you. Watching last week’s weather on TV is not much use… However I would still like to know some history so that I can - if I wish - examone the history to compare it to other plants.
Saving the data in InfluxDB for a week would be ideal. Do you know how I can keep just this entity for a week. I guess It would go into confiuration.yaml in the recorder section. is tha tright? If so what’s the syntax?
I’m sorry, different retention periods per device is not currently possible in the recorder config. The default is 10 days and can be changed, but it applies to all history.
I’m not familiar with influxDB so can’t say whether that would allow you to set custom retention periods per device/entity.
Thanks anyway for your help. I had read somwhere that this may be possible. I shall need more reading to find out if InfluxDB is capable of this. I like your idea.
Well, it worked. Thank you all very much. It turned out that all I had to do was to comment out the name: of the id I did not wish to be transmitted to HA from the ESP. Once I had stopped the rapid fire data stream I just needed to put in the template as suggested. I set this to 600 seconds and now I get fast response on the soil moisture sensor and a 10 minute Dashboard monitor in HA.
Here is the final code.
Thanks again.
- platform: gpio
pin: D2
id: water_pump
icon: mdi:water-pump
name: "Water Pump"
sensor: # Cheapo Soil Humidity Sensor
- platform: adc
pin: A0
id: indoor_hydrangea_humidity_percent
internal: true # Stops sending data to HA
icon: mdi:water-percent
#name: "Indoor Hydrangea Soil Moisture"
unit_of_measurement: "%"
accuracy_decimals: 1
# Adjust the sensor output to give meaningful % readings
filters:
- calibrate_linear:
- 0.00568 -> 0.0
# - 0.04880 -> 10.0
# - 0.01367 -> 20.0
# - 0.02051 -> 30.0
# #- 0.02834 -> 40.0
- 0.02637 -> 40.0
# - 0.03613 -> 50.0
# - 0.04102 -> 60.0
# - 0.05000 -> 70.0
# - 0.06555 -> 80.0
# - 0.07050 -> 90.0
# - 0.01200 -> 100.0
# Average several readings
- sliding_window_moving_average:
window_size: 20
send_every: 5
# Send the output to HA
- lambda: return x;
# Turn the Pump relay on and off
on_value_range:
- above: 55.0 # Turn off at 55%
then:
- switch.turn_off: water_pump # Pump relay off
- below: 42.0 # Turn on at 42%
then:
- switch.turn_on: water_pump # Pump relay on
update_interval: 1s
# Wifi Signal Strength
- platform: wifi_signal
id: 'indoor_hydrangea_wifi_db'
name: "Indoor Hydrangea Water WiFi Signal"
update_interval: 600s
# Send data to HA slower than it is generated by the sensor
# so as not to clutter up the database.
- platform: template
name: "Indoor Hydrangea Soil Moisture summary"
id: indoor_hydrangea_humidity_to_ha
icon: mdi:water-percent
unit_of_measurement: "%"
lambda: return id(indoor_hydrangea_humidity_percent).state * 1;
update_interval: 600s # 600s = 10 mins