How to monitor how often turns on water pump?

Hi.

I have a waterpump, that pumps water to my house water system, every time the faucet is opened, someone takes shower or uses wc, etc

Water pump turns on for about 3-4 seconds (to get the pressure in the system) and then turns off. I am trying to get the count how many times has it turned on in a day. At this time i was unable to get exact count. I have tried three different smart outlets, to check the Wolts or Amps, when the pump is on. With simple logic as this


      water_pump_tplink:
        friendly_name: Water Pump tplink
        value_template: >-
          {% if states('sensor.water_pump_watts')|float > 0 %}
            on
          {% else %}
           off
          {% endif %}

The problem is that the outlets report the W or A state with latecny or refresh ir relly slow, so the template sensor misses a lot of pump turn ons. Like if the person is in the shower, the pump turns on very often for a short periods of time, so the outlet does not keep up with the real count.

I have tried

TP-link kasa WIFI smart outlet tp link hs110 - has the closest update interval, if using automation

- alias: "Update HS110 TP link"
  initial_state: 'on'
  trigger:
    - platform: time_pattern
      seconds: '/2' 
  action:
    - service: homeassistant.update_entity
      data:
        entity_id: 
          - switch.water_pump

But HA logs are full of warnings, that is already running, and still not perfect.

Blitzwolf BW-SHP2 wifi outlet (with Tasmota)

On tasmota page, the Amps and Watts are updated fast, but in hassio interface it comes with big latency and does not update so often.

Xiaomi zigbee ZNCZ04LM (zigbee2mqtt)

really slow update in HA interface.

Maybe someone have any ideas how to monitor the turn on count of the pump, maybe using some other devices.
Thanks.

Wire a relay coil (with appropriate voltage rating) in parallel (not series!) with your pump. Use the voltage free relay contacts to trigger a fast acting sensor like a zigbee or zwave door/window sensor or a GPIO on a Sonnof.

1 Like

Have you tried playing with PowerDelta in Tasmota?

Thanks for great ideas.

Did I understand correcly, something like this:
wpump

No havent tried, checking the documentation now. Could it be possible to create a rule that sends MQTT message with value 1 or 0 depending if the ENERGY#Current>0 and send 0 ENERGY#Current=0 . Or am I missing something.

Thanks.

Something like that. Just to be clear:

426c86b92b9c2ec9fbb9fe1aaa146301644c9045

The problem with using powerdelta in Tasmota is that it does not report when power turns off.

Can you use esphome for the energy monitoring? This way you will skip mqtt and the slow information report for A or W.
You can use :
update_interval: 1s

1 Like

You could do that, though to prevent saturating your network with useless traffic it would be wise to use the delta filter as well.

OP is complaining about slow response or not catching the power on/off at all , not about useless traffic. He has the needed devices already , no need for additional coils, reeds, relays and others. May be this is just the thing that the OP needs.
There is also the posibility of an automation on the device itself.

  https://esphome.io/guides/automations.html#automation
1 Like

As the water pump is connected to electicity all the time, the power must be on at all time. I just need to catch the moment it starts to pump (when there is spike in Watts)

I think esphome could be the answer, will need to experiment with it. Thanks.

Using 1 second update with the delta filter you get both a fast response and no unneeded network traffic.

1 Like

Got SHP2 working with ESPhome, and looks like if update interval is 1s, Wattage has decent update time. But could you pelase explane more about the delta. If I need to get all values that are abowe 0 (so it means that the pump is working) I need to set delta, lets say to 1?

my sensor config in ESPhome

sensor:
  - platform: hlw8012
    sel_pin:
      number: GPIO12
      inverted: True
    cf_pin: GPIO04
    cf1_pin: GPIO05
    current_resistor: ${current_res}
    voltage_divider: ${voltage_div}
    current:
      name: ${plug_name}_Amperage
      icon: mdi:current-ac
      unit_of_measurement: A
    voltage:
      name: ${plug_name}_Voltage
      icon: mdi:flash-circle
      unit_of_measurement: V
    power:
      name: ${plug_name}_Wattagefi
      icon: mdi:flash-outline
      unit_of_measurement: W
      id: ${plug_name}_Wattage
      filters:
        - delta: 1.0
    change_mode_every: 8
    update_interval: 1s
1 Like

The delta filter only sends values when the value has changed by the delta amount (up or down) from the previous reading.

So if you have a delta of 1, only the readings marked like this below would be sent:

0.1, 0, 0.2, 0.1, 0.1 , 1.1, 0, 0.1, 0, 0.2, 0.1, 5, 10, 10.1, 20, 50, 51, 52, 52.1

If you only want to know when your pump turns on you can actually set the delta quite a bit higher, 20% of the pump running wattage would only send readings when the pump turned on or off, but it would make it useless for graphing power, if you want to do that.

Watch the long term noise of your pump readings when off and when on, set the delta just a little higher than the noise. So if it fluctuates 0.2W when off and 2W when on, set the delta to something above 2 and you will only see the power changes, not the noise. But the resolution (steps) of your readings will be this value above 2.

1 Like

Looks like Im getting somewhere :slight_smile:

sensor:
  - platform: hlw8012
    sel_pin:
      number: GPIO12
      inverted: True
    cf_pin: GPIO04
    cf1_pin: GPIO05
    current_resistor: ${current_res}
    voltage_divider: ${voltage_div}
    current:
      name: ${plug_name}_Amperage
      icon: mdi:current-ac
      unit_of_measurement: A
    voltage:
      name: ${plug_name}_Voltage
      icon: mdi:flash-circle
      unit_of_measurement: V
    power:
      name: ${plug_name}_Wattagefi
      icon: mdi:flash-outline
      unit_of_measurement: W
      id: ${plug_name}_Wattage
      filters:
        - delta: 800
    change_mode_every: 8
    update_interval: 1s

binary_sensor:
  - platform: template
    name: "Water pump state"
    lambda: |-
      if (id(${plug_name}_Wattage).state > 800) {
        return true;
      } else {
        return false;
      }    

Now in HA I see only values abow 800W so the other values are not flooded, but on ESP log, I see every second this

[17:26:11][D][sensor:092]: 'esp_outlet4_Amperage': Sending state 0.00000 A with 2 decimals of accuracy
[17:26:12][D][hlw8012:063]: Got power=0.0W, current=0.0A
[17:26:12][D][sensor:092]: 'esp_outlet4_Amperage': Sending state 0.00000 A with 2 decimals of accuracy
[17:26:13][D][hlw8012:063]: Got power=0.0W, current=0.0A
[17:26:13][D][sensor:092]: 'esp_outlet4_Amperage': Sending state 0.00000 A with 2 decimals of accuracy
[17:26:14][D][hlw8012:063]: Got power=0.0W, current=0.0A
[17:26:14][D][sensor:092]: 'esp_outlet4_Amperage': Sending state 0.00000 A with 2 decimals of accuracy
[17:26:15][D][hlw8012:063]: Got power=0.0W, current=0.0A
[17:26:15][D][sensor:092]: 'esp_outlet4_Amperage': Sending state 0.00000 A with 2 decimals of accuracy
[17:26:16][D][hlw8012:063]: Got power=0.0W, current=0.0A
[17:26:16][D][sensor:092]: 'esp_outlet4_Amperage': Sending state 0.00000 A with 2 decimals of accuracy

It looks that I must somehow limit the update inteval also for Amperage and Current, but is does not take any update_intervals as it is set up for all sensor. How to fix that?
Thanks :slight_smile:

Hmm. Tricky. If you limit the current and voltage update rate you will limit the power calculation.

A different approach could be to set all three sensors to internal only with no filtering:

sensor:
  - platform: hlw8012
    sel_pin:
      number: GPIO12
      inverted: True
    cf_pin: GPIO04
    cf1_pin: GPIO05
    current_resistor: ${current_res}
    voltage_divider: ${voltage_div}
    current:
      name: ${plug_name}_Amperage
      id: amps
      icon: mdi:current-ac
      unit_of_measurement: A
      internal: true
    voltage:
      name: ${plug_name}_Voltage
      id: volts
      icon: mdi:flash-circle
      unit_of_measurement: V
      internal: true
    power:
      name: ${plug_name}_Wattagefi
      id: watts
      icon: mdi:flash-outline
      unit_of_measurement: W
      id: ${plug_name}_Wattage
      internal: true
    update_interval: 1s

Then use throttled template sensors for sending the data:

  - platform: template
    name: "Voltage"
    icon: mdi:flash-circle
    unit_of_measurement: V
    lambda: |-
       return id(volts).state;
    update_interval: 1s
    filters:
      - sliding_window_moving_average:
          window_size: 30
          send_every: 30
  - platform: template
    name: "Current"
    icon: mdi:current-ac
    unit_of_measurement: A
    lambda: |-
       return id(amps).state;
    update_interval: 1s
    filters:
      - sliding_window_moving_average:
          window_size: 30
          send_every: 30
  - platform: template
    name: "Power"
    icon: mdi:current-ac
    unit_of_measurement: W
    lambda: |-
       return id(watts).state;
    update_interval: 1s
    filters:
      - delta: 800

Totally untested, no idea if it will work. :slight_smile:

2 Likes

Thanks. It does work, but still it updates frequently. I think I will leave as 1s update time as the first version, and will see how it goes.
Thank you all for help.

1 Like

I think “SetOption21 1” should make it report power even when switched off.

The answer was so simple, I dont know why it came to head just after a year. :man_facepalming:t2:
Maybe it could come handy for someone.
I can use tasmota rules, to send custom mqtt payload when the consumed power of the tasmotized outlet is bigger than X and send different payload when power is less than X.

on tasmota device:

Rule1 ON Energy#Power>10 DO Publish tele/waterpump/state {"State":"On"} ENDON ON Energy#Power<10 DO Publish tele/waterpump/state {"State":"Off"} ENDON
rule1 5
Rule1 1

rule1 5 so the rule fires only once, when it hits more/less than X

binary_sensor:

  - platform: mqtt
    name: "Water pump state"
    state_topic: "tele/waterpump/state"
    value_template: "{{ value_json['State']}}"
    payload_on: 'On'
    payload_off: 'Off'
    device_class: power
    qos: 1

works perfectly