I have a Hall sensor mounted on my gasmeter. Due to the week signal, it doesn’t work as a switch. The analog signal though is strong enough to consistantly detect the pulses.
It works just fine for the pulse count, but I also would like to calculate the heating power. Pulse meter only works on a digital pin, so I tried to determine the interval between on-on and on-off.
I came up with the code below, but I fail to get the states from the timers to publish.
Can anyone put me on the right track?
Thanks in advance,
esphome:
name: d1minilolin-01
friendly_name: D1MiniLOLIN-01
esp8266:
board: esp01_1m
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "MeItImNVFSKIxMucF3h2hCw2eUJxR7gwXWCX0z4f5Ow="
ota:
password: "f3605d46be86c79d06ca0ff3cf767bde"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "D1Minilolin-01 Fallback Hotspot"
password: "KoLWfxrgkzkK"
captive_portal:
- platform: adc
pin: A0
id: gasmeter_hall_measurement
internal: true
update_interval: 100ms
raw: true
name: "Gasmeter Hall measurement"
filters:
- lambda: return 1024-x;
- delta: 2.0
- platform: uptime
name: "Time Since Last On"
id: time_since_last_on
internal: True
- platform: template
name: "gasmeterpulsetijd on-on"
id: gasmeterpulsetijd_on_on
device_class: duration
unit_of_measurement: "s"
state_class: "measurement"
icon: "mdi:clock-fast"
accuracy_decimals: 2
- platform: template
name: "gasmeterpulsetijd on-off"
id: gasmeterpulsetijd_on_off
device_class: duration
unit_of_measurement: "s"
state_class: "measurement"
icon: "mdi:clock-fast"
accuracy_decimals: 3
binary_sensor:
- platform: analog_threshold
name: "Gasmeterteller 10liter"
sensor_id: gasmeter_hall_measurement
threshold:
upper: 476 #was 480
lower: 467 #was 470
on_press:
then:
- lambda: |-
if (id(starttijdpulse) > 0) {
id(pulsduur_onon) = id(time_since_last_on).state - id(starttijdpulse);
id(starttijdpulse) = id(time_since_last_on).state;
id(gasmeterpulsetijd_on_on).publish_state(id(pulsduur_onon)/1000);
}
on_release:
then:
- lambda: |-
if (id(starttijdpulse) > 0) {
id(pulsduur_onoff) = id(time_since_last_on).state - id(starttijdpulse);
id(gasmeterpulsetijd_on_off).publish_state(id(pulsduur_onoff)/1000);
}
globals:
- id: total_pulses
type: int
initial_value: '920'
- id: starttijdpulse
type: long
initial_value: '0'
- id: pulsduur_onon
type: long
initial_value: '0'
- id: pulsduur_onoff
type: long
initial_value: '0'