Advertisement
SimyriK

my_esphome_energymonitor

Aug 16th, 2023
1,529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.11 KB | None | 0 0
  1. esphome:
  2.   name: "esphome-energymonitor-1"
  3.   friendly_name: EnergyMonitor_1
  4.   on_boot:
  5.     then:
  6.     - pulse_meter.set_total_pulses:
  7.         id: count
  8.         value: !lambda "return id(total_pulses);"
  9.  
  10. esp8266:
  11.   board: nodemcuv2
  12.   restore_from_flash: true
  13.  
  14. globals:
  15.   - id: total_pulses
  16.     type: float
  17.     restore_value: yes
  18.  
  19. logger:
  20.  
  21. ota:
  22.  
  23. wifi:
  24.   ssid: !secret wifi_ssid
  25.   password: !secret wifi_password
  26.  
  27.   # Enable fallback hotspot (captive portal) in case wifi connection fails
  28.   ap:
  29.     ssid: "Esphome-Web-fafafa"
  30.     password: "fafafa"
  31.  
  32. captive_portal:
  33.    
  34. mqtt:
  35.   broker: 10.11.12.13
  36.   port: 1883
  37.   username: admin
  38.   password: !secret mqtt_password
  39.   discovery: true
  40.   on_connect:
  41.     - mqtt.publish:
  42.         topic: energymonitorstatus
  43.         payload: online
  44.         retain: true
  45.   # topic_prefix: esphome/energymonitor/01
  46.   birth_message:
  47.     topic: energymonitorstatus
  48.     payload: online
  49.     retain: true
  50.   will_message:
  51.     topic: energymonitorstatus
  52.     payload: offline
  53.     retain: true
  54.   on_message:
  55.     topic: total
  56.     then:
  57.       - pulse_meter.set_total_pulses:
  58.           id: count
  59.           value: !lambda "return atof(x.c_str()) / 0.0003125;"
  60.  
  61.  
  62. preferences:
  63.   flash_write_interval: 5min
  64.  
  65. sensor:
  66.   - platform: pulse_meter
  67.     pin: D7
  68.     unit_of_measurement: 'kW'
  69.     name: 'Electricity Usage'
  70.     id: count
  71.     internal_filter: 100ms
  72.     accuracy_decimals: 3
  73.     retain: true
  74.     filters:
  75.       - multiply: 0.01875 #=1/(3200/60)
  76.     on_value:
  77.       - mqtt.publish:
  78.           topic: esphome/energymonitor/01/count
  79.           payload: !lambda |-
  80.             return to_string(id(count).state);
  81.     total:
  82.       name: "Electricity Total"
  83.       id: total
  84.       unit_of_measurement: "kWh"
  85.       accuracy_decimals: 3
  86.       filters:
  87.         - multiply: 0.0003125 #=1/3200
  88.       retain: true
  89.       on_value:
  90.         - mqtt.publish:
  91.             retain: true
  92.             topic: esphome/energymonitor/01/total
  93.             payload: !lambda |-
  94.               id(total_pulses) = id(total).raw_state;
  95.               return to_string(id(total).state);
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement