Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- esphome:
- name: "esphome-energymonitor-1"
- friendly_name: EnergyMonitor_1
- on_boot:
- then:
- - pulse_meter.set_total_pulses:
- id: count
- value: !lambda "return id(total_pulses);"
- esp8266:
- board: nodemcuv2
- restore_from_flash: true
- globals:
- - id: total_pulses
- type: float
- restore_value: yes
- logger:
- ota:
- wifi:
- ssid: !secret wifi_ssid
- password: !secret wifi_password
- # Enable fallback hotspot (captive portal) in case wifi connection fails
- ap:
- ssid: "Esphome-Web-fafafa"
- password: "fafafa"
- captive_portal:
- mqtt:
- broker: 10.11.12.13
- port: 1883
- username: admin
- password: !secret mqtt_password
- discovery: true
- on_connect:
- - mqtt.publish:
- topic: energymonitorstatus
- payload: online
- retain: true
- # topic_prefix: esphome/energymonitor/01
- birth_message:
- topic: energymonitorstatus
- payload: online
- retain: true
- will_message:
- topic: energymonitorstatus
- payload: offline
- retain: true
- on_message:
- topic: total
- then:
- - pulse_meter.set_total_pulses:
- id: count
- value: !lambda "return atof(x.c_str()) / 0.0003125;"
- preferences:
- flash_write_interval: 5min
- sensor:
- - platform: pulse_meter
- pin: D7
- unit_of_measurement: 'kW'
- name: 'Electricity Usage'
- id: count
- internal_filter: 100ms
- accuracy_decimals: 3
- retain: true
- filters:
- - multiply: 0.01875 #=1/(3200/60)
- on_value:
- - mqtt.publish:
- topic: esphome/energymonitor/01/count
- payload: !lambda |-
- return to_string(id(count).state);
- total:
- name: "Electricity Total"
- id: total
- unit_of_measurement: "kWh"
- accuracy_decimals: 3
- filters:
- - multiply: 0.0003125 #=1/3200
- retain: true
- on_value:
- - mqtt.publish:
- retain: true
- topic: esphome/energymonitor/01/total
- payload: !lambda |-
- id(total_pulses) = id(total).raw_state;
- return to_string(id(total).state);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement