I’ve made an energy meter using the ESP home pulse counter. It appears to work when fed pulses on my bench, but I’d like to initialise the kWh total to the same value as on my electricity meter. I’d also like to be able to edit this value from within HA in case I loose counts for some reason. The pulse resetting fragment example given at Pulse Counter Sensor — ESPHome is a bit unclear to me. Specifically the line ‘id: pulse_counter_id’. I don’t know what that refers to and my yaml does not like it. See below in the services section of the code, the error I get is pasted in as a comment.
Thanks for any guidance, I’ve not used ESP home before, so I’m probably missing something obvious. A working example would help a lot.
J.
PS. Apologies if the code formatting is problematic, I’m getting an unformatted code warniing even though I’ve done the 3 backticks thing…
esphome:
name: esphome-web-xxxxxx
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
# Set pulse counter total from home assistant using this service call:
services:
- service: set_pulse_total
variables:
new_pulse_total: int
then:
- pulse_counter.set_total_pulses:
id: pulse_counter_id # gives error - Couldn't find ID 'pulse_counter_id'. Please check you have defined an ID with that name in your configuration.
value: !lambda 'return new_pulse_total;'
ota:
wifi:
networks:
- ssid: !secret wifi_ssid
password: !secret wifi_password
- ssid: !secret wifi_ssid_rpt
password: !secret wifi_password
- ssid: !secret wifi_ssid_rpt2
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esphome-Web-xxxxxx"
password: "xxxxxx"
captive_portal:
switch:
- platform: gpio
name: "Output_5"
pin: 5
binary_sensor:
- platform: gpio
name: "Input_12"
pin:
number: 12
inverted: false
mode:
input: true
pullup: true
sensor:
- platform: uptime
name: Smart Meter Uptime
- platform: wifi_signal
name: Smart Meter WiFi signal
- platform: pulse_counter
pin: 4
unit_of_measurement: 'kW'
name: 'Power Meter'
filters:
- multiply: 0.06 # (60s/1000 pulses per kWh)
total:
unit_of_measurement: 'kWh'
accuracy_decimals: 2
icon: mdi:gauge
name: 'Energy Meter'
filters:
- multiply: 0.001 # (1/1000 pulses per kWh)
Presuming its 1000 pulses per kwh, create a sensor from your esp that just measures used kwh from 0. You can the use the utility meter helper to give you a count that matches your meter as you can ‘calibrate it’ with current reading when you want.
I have done this with a frient energy meter pulse counter and i have very accurate readings.
Id say yes using an automation that calls the service when the state of the input number changes and passes the value of it. There maybe other ways but not aware of any.
The HA utility meter suggested works for me too. I use the manual config on utility meter, not the helper. However to answer the question from jmcc:
I think the ESPHome doc needed to make clear what id was being reset. The docs mention a generic “pulse_counter_id”. It ought to be an ID you need to attach to your sensor. In my case below that ID is ‘myelectricity’. Here’s what I did and what works to reset the total.
ELECTRICITY METER
The following code reads the red flashes from the electricity meter. It produces two entities one that measures the electric power in kw, the other gives energy in kWh which is more useful. The code appears to add a service to HA - scroll down for how to test it. I’m scratching in the dark myself so please share any improvements you make.
TO TEST THE RESET FEATURE
Go to Developer Tools > Services > ESPHome: meter_set_pulse_total > Enter a value for new_pulse_total (eg 0 ).
TO USE THE RESET FEATURE
Make an automation that say, Triggers at midnight and as an Action Calls the service: ESPHome: meter_set_pulse_total and enter the value (eg 0)
Hi there, could you please explain how you were able to use the Utility Meter helper?
I created one and called it pulse_counter_id however that still gives the error
Couldn’t find ID ‘pulse_counter_id’. Please check you have defined an ID with that name in your configuration.
Thanks in advance.