Skip to content

Instantly share code, notes, and snippets.

@nickknissen
Created April 22, 2023 06:32
Show Gist options
  • Save nickknissen/70f0eeeb527b634f234c53b7f733301a to your computer and use it in GitHub Desktop.
Save nickknissen/70f0eeeb527b634f234c53b7f733301a to your computer and use it in GitHub Desktop.
Carlo Gavazzi EM340 pulse out monitor
substitutions:
energy_name: Heatpump
esphome:
name: heatpump-energy
esp32:
board: esp32dev
framework:
type: esp-idf
logger:
#captive_portal:
improv_serial:
api:
services:
- service: meter_reading_kwh
variables:
meter_value: float
then:
- globals.set:
id: ${energy_name}_initial_kwh_usage
value: !lambda "return ( meter_value ) ;"
ota:
password: "f9a8fc5386d47d53b7993eab4fbff620"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
button:
- platform: restart
name: " heatpump energy Restart device"
### NEW
globals:
- id: ${energy_name}_initial_kwh_usage
type: float
restore_value: yes
initial_value: '698.24'
- id: ${energy_name}_total_kwh_pulses
type: int
restore_value: yes
number:
- platform: template
id: ${energy_name}_select_pulse_rate
name: '${energy_name} Pulsrate kWh'
optimistic: true
mode: box
min_value: '10'
max_value: '4000'
step: '10'
restore_value: yes
initial_value: '1000'
binary_sensor:
- platform: gpio
id: ${energy_name}_internal_pulse_counter
name: ${energy_name} Pulse Sensor kwh
pin:
number: GPIO02
mode: INPUT_PULLUP
on_press:
- then:
lambda: id(${energy_name}_total_kwh_pulses) += 1;
sensor:
- platform: pulse_meter
pin:
number: GPIO02
mode: INPUT_PULLUP
name: "${energy_name} Current energy"
id: actual_power
icon: "mdi:flash"
# internal_filter: ${impulslengte}
accuracy_decimals: 3
unit_of_measurement: 'kW'
state_class: measurement
device_class: power
filters:
lambda: return x * (60.0 / id(${energy_name}_select_pulse_rate).state);
total:
unit_of_measurement: 'kWh'
name: "${energy_name} Total consumed"
id: ${energy_name}_total_energy_consumed
state_class: total_increasing
device_class: energy
icon: "mdi:flash"
accuracy_decimals: 3
filters:
- lambda: return x * (1.0 / id(${energy_name}_select_pulse_rate).state);
- platform: template
id: ${energy_name}_kwh_total
name: "${energy_name} Total consumption since start"
state_class: "total_increasing"
device_class: energy
icon: "mdi:flash"
update_interval: 1s
unit_of_measurement: 'kWh'
accuracy_decimals: 3
lambda: return id(${energy_name}_initial_kwh_usage) + (id(${energy_name}_total_kwh_pulses) * 0.001);
- platform: template
id: ${energy_name}_kwh_pulses
name: "${energy_name} kwh pulses total"
state_class: "total_increasing"
lambda: return id(${energy_name}_total_kwh_pulses);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment