Value of sensor pulse_meter after reset of esp8266

Hi,
At midnight I reset my esp8266 so I am able to get the daily score of my used water.
I use an proximity device in combination withth esphome sensor pulse_meter.
Recently I discovered that the sensor returns “unknown” after a reboot instead of the earlier value of 0.
Anyone an idea how to get the value 0 at reboot?
Thank you!
Was

Best to post your configuration.

Likely you can use an on_boot: automation to set it to zero.

Or alternatively you might be able to restore the previous value if you wish.

1 Like

Hi Mahko,

Thanks for the swift reply:

hereby a part of my config:

esphome:
name: “esp08”
friendly_name: “esp08”
comment: “Kelder - Water meter”
platform: ESP8266
board: esp01_1m

/…
…/
sensor:

  • platform: pulse_meter
    id: sensor_pulse_meter
    pin: 14
    internal_filter: 200 ms
    name: “Water usage”
    icon: “mdi:water”
    unit_of_measurement: “rpm”
    accuracy_decimals: 0
    timeout: 2min
    total:
    id: sensor_pulse_meter_total
    name: “Water usage Total”
    icon: “mdi:water”
    unit_of_measurement: “L”
    accuracy_decimals: 0

I tried
esphome:
name: “esp08”
friendly_name: “esp08”
comment: “Kelder - Water meter”
platform: ESP8266
board: esp01_1m
on_boot:
then:
- sensor_pulse_meter: ‘0’
- sensor_pulse_meter_total: ‘0’

But that does not work and I can not find how to set the value of a sensor …

Not an direct answer to your problem, but please read this: How to help us help you - or How to ask a good question and especially the info about formatting code. This largely improves the readability of the code in your posts.

How are you resetting your esp8266? Are you restarting the device because if so, the unknown value is there because your home assistant server can’t talk to the esp8266 untill it has restarted and during this time the value is “unknown”.

Can you not reset your total pulse count, or will that break other parts of your code? (Again like others have mentioned, it helps if you share all relevant code).

If you aren’t doing so already, have a look at Reseting Your Total Pulse Count (the last section on this page). This also lets you input a starting value.

Hi, hereby the current config.
The purpose of this config is:

  1. determine total water usage per day; the esp8266 is reset at midnight by a HA automation
  2. determine batch sizes of water usage; the batch counter is reset if no pulses are recieved for 2min,
    the value of the total counter is stored; when water is used again the current total - the stored value of the total is returned to HA and shown on a display (other esp).
    The code is a bit strange as in previous esp-home versions, the code reacted starnge after a reset, but the pulse_meter and pulse_meter_total got value 0 after a reboot.

esphome:
name: “esp08”
friendly_name: “esp08”
comment: “Kelder - Water meter”
platform: ESP8266
board: esp01_1m

Enable logging

logger:

Enable Home Assistant API

api:

ota:
password: “xxxx”

wifi:
domain: xxxx
ssid: “xxxx”
password: “xxxx!”

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “ESP08 Fallback Hotspot”
password: “xxxx”

captive_portal:

Enable time component to reset energy at midnight

time:

  • platform: sntp
    id: my_time

globals:

  • id: batchstart
    type: float
    initial_value: ‘0.0’
    restore_value: no
  • id: batchstart_mem
    type: float
    initial_value: ‘0.0’
    restore_value: no
  • id: lock_mem
    type: bool
    initial_value: ‘false’
    restore_value: no

sensor:

  • platform: pulse_meter
    id: sensor_pulse_meter
    pin: 14
    internal_filter: 200 ms
    name: “Water usage”
    icon: “mdi:water”
    unit_of_measurement: “rpm”
    accuracy_decimals: 0
    timeout: 2min

    total:
    id: sensor_pulse_meter_total
    name: “Water usage Total”
    icon: “mdi:water”
    unit_of_measurement: “L”
    accuracy_decimals: 0

  • platform: template
    id: sensor_pulse_batch_mem
    name: “Water usage Batch Memorized”
    accuracy_decimals: 0
    unit_of_measurement: “L”
    icon: “mdi:water”
    update_interval: 1s
    lambda: !lambda |-
    if ((id(sensor_pulse_meter_total).state) == 0)
    { id(batchstart_mem) = 0;
    id(lock_mem) = false;
    }
    if ((id(sensor_pulse_meter).state) > 0)
    { if (id(lock_mem) == false)
    { id(batchstart_mem) = (id(sensor_pulse_meter_total).state) - 1;
    id(lock_mem) = true;
    }
    }
    else
    { id(lock_mem) = false;
    }
    return ((id(sensor_pulse_meter_total).state) - id(batchstart_mem));

  • platform: template
    id: sensor_pulse_batch
    name: “Water usage Batch”
    accuracy_decimals: 0
    unit_of_measurement: “L”
    icon: “mdi:water”
    update_interval: 1s
    lambda: !lambda |-
    if ((id(sensor_pulse_meter).state) == 0)
    { id(batchstart) = (id(sensor_pulse_meter_total).state);
    }
    return ((id(sensor_pulse_meter_total).state) - (id(batchstart)));

switch:

  • platform: restart
    id: switch_restart
    name: “esp08 restart”

Hi there

I finally got it work, using on_boot

The (for now) final working configuration is (perhaps it could use some cleanup):

esphome:
name: “esp08”
friendly_name: “esp08”
comment: “Kelder - Water meter”
platform: ESP8266
board: esp01_1m
on_boot:
- sensor.template.publish:
id: sensor_pulse_batch_mem
state: 0
- sensor.template.publish:
id: sensor_pulse_batch
state: 0
- sensor.template.publish:
id: sensor_pulse_meter_total
state: 0

Enable logging

logger:

Enable Home Assistant API

api:

ota:
password: “xxxxxxxxxx”

wifi:
domain: .xxxxxxxxxx.local
ssid: “xxxxxxxxxx”
password: “xxxxxxxxxx”

Enable fallback hotspot (captive portal) in case wifi connection fails

ap:
ssid: “ESP08 Fallback Hotspot”
password: “xxxxxxxxxx”

captive_portal:

Enable time component to reset energy at midnight

time:

  • platform: homeassistant
    id: homeassistant_time
    on_time_sync:
    then:
    - logger.log: “Synchronized system clock”
    on_time:
    • seconds: 0
      minutes: 0
      hours: 0
      then:
      • pulse_meter.set_total_pulses:
        id: sensor_pulse_meter
        value: 0

globals:

  • id: batchstart
    type: float
    initial_value: ‘0.0’
    restore_value: no
  • id: batchstart_mem
    type: float
    initial_value: ‘0.0’
    restore_value: no
  • id: lock_mem
    type: bool
    initial_value: ‘false’
    restore_value: no

sensor:

  • platform: pulse_meter
    id: sensor_pulse_meter
    pin: GPIO14
    internal_filter: 200 ms
    name: “Water usage”
    icon: “mdi:water”
    unit_of_measurement: “rpm”
    accuracy_decimals: 0
    timeout: 120s

    total:
    id: sensor_pulse_meter_total
    name: “Water usage Total”
    icon: “mdi:water”
    unit_of_measurement: “L”
    accuracy_decimals: 0

  • platform: template
    id: sensor_pulse_batch_mem
    name: “Water usage Batch Memorized”
    accuracy_decimals: 0
    unit_of_measurement: “L”
    icon: “mdi:water”
    update_interval: 1s
    lambda: !lambda |-
    if ((id(sensor_pulse_meter_total).state) == 0)
    { id(batchstart_mem) = 0;
    id(lock_mem) = false;
    }
    if ((id(sensor_pulse_meter).state) > 0)
    { if (id(lock_mem) == false)
    { id(batchstart_mem) = (id(sensor_pulse_meter_total).state) - 1;
    id(lock_mem) = true;
    }
    }
    else
    { id(lock_mem) = false;
    }
    return ((id(sensor_pulse_meter_total).state) - id(batchstart_mem));

  • platform: template
    id: sensor_pulse_batch
    name: “Water usage Batch”
    accuracy_decimals: 0
    unit_of_measurement: “L”
    icon: “mdi:water”
    update_interval: 1s
    lambda: !lambda |-
    if ((id(sensor_pulse_meter).state) == 0)
    { id(batchstart) = (id(sensor_pulse_meter_total).state);
    }
    return ((id(sensor_pulse_meter_total).state) - (id(batchstart)));

switch:

  • platform: restart
    id: switch_restart
    name: “esp08 restart”