|
| 1 | +# ---------------------------------------------------------------------------------------------------- |
| 2 | +# Power Meter - Enphase Envoy (Firmware < 7.x, no authentication required) |
| 3 | +# |
| 4 | +# This power meter reads the grid import/export power from an Enphase Envoy gateway |
| 5 | +# using the local HTTP API. It is compatible with older Envoy and Envoy-S devices |
| 6 | +# that do not require token-based authentication. |
| 7 | +# |
| 8 | +# Required variable: |
| 9 | +# power_meter_ip_address: IP address or hostname of the Envoy (e.g. "192.168.1.50" |
| 10 | +# or "envoy.local") |
| 11 | +# |
| 12 | +# Usage example in your main yaml: |
| 13 | +# packages: |
| 14 | +# solar_router: |
| 15 | +# url: https://github.com/XavierBerger/Solar-Router-for-ESPHome |
| 16 | +# refresh: 1d |
| 17 | +# files: |
| 18 | +# - path: solar_router/common.yaml |
| 19 | +# - path: solar_router/power_meter_enphase_envoy.yaml |
| 20 | +# vars: |
| 21 | +# power_meter_ip_address: "192.168.1.50" |
| 22 | +# |
| 23 | +# API endpoint used: GET http://<envoy>/production.json |
| 24 | +# The "net-consumption" measurement (consumption[1].wNow) represents the power |
| 25 | +# exchanged with the grid: |
| 26 | +# - Positive value → energy is drawn FROM the grid |
| 27 | +# - Negative value → energy is PUSHED TO the grid (solar surplus) |
| 28 | +# ---------------------------------------------------------------------------------------------------- |
| 29 | + |
| 30 | +# ---------------------------------------------------------------------------------------------------- |
| 31 | +# Sensor updated every second to give feedback in Home Assistant |
| 32 | +# ---------------------------------------------------------------------------------------------------- |
| 33 | +sensor: |
| 34 | + # Sensor showing the actual power exchange with the grid |
| 35 | + - id: real_power |
| 36 | + platform: template |
| 37 | + name: "Real Power" |
| 38 | + device_class: "power" |
| 39 | + unit_of_measurement: "W" |
| 40 | + update_interval: 1s |
| 41 | + |
| 42 | +# ---------------------------------------------------------------------------------------------------- |
| 43 | +# Use http request component |
| 44 | +# ---------------------------------------------------------------------------------------------------- |
| 45 | +http_request: |
| 46 | + id: http_request_data |
| 47 | + useragent: esphome/device |
| 48 | + timeout: 10s |
| 49 | + verify_ssl: false |
| 50 | + |
| 51 | +# ---------------------------------------------------------------------------------------------------- |
| 52 | +# Define scripts for power collection |
| 53 | +# ---------------------------------------------------------------------------------------------------- |
| 54 | +script: |
| 55 | + # Enphase Envoy script reads the grid power from the local production.json endpoint. |
| 56 | + # The "net-consumption" entry (index 1 of the consumption array) reports the net |
| 57 | + # power exchanged with the grid. A positive value means power is consumed from the |
| 58 | + # grid; a negative value means excess solar power is being exported to the grid. |
| 59 | + - id: power_meter_source |
| 60 | + mode: single |
| 61 | + then: |
| 62 | + - if: |
| 63 | + condition: |
| 64 | + wifi.connected: |
| 65 | + then: |
| 66 | + - http_request.get: |
| 67 | + url: http://${power_meter_ip_address}/production.json |
| 68 | + capture_response: true |
| 69 | + max_response_buffer_size: 4096 |
| 70 | + on_response: |
| 71 | + then: |
| 72 | + - lambda: |- |
| 73 | + json::parse_json(body, [](JsonObject root) -> bool { |
| 74 | + // consumption[1] is the "net-consumption" meter: |
| 75 | + // positive → drawing from grid |
| 76 | + // negative → exporting to grid (solar surplus) |
| 77 | + JsonArray consumption = root["consumption"]; |
| 78 | + if (consumption.size() >= 2) { |
| 79 | + id(real_power).publish_state(consumption[1]["wNow"].as<float>()); |
| 80 | + } |
| 81 | + return true; |
| 82 | + }); |
| 83 | +
|
| 84 | +# ---------------------------------------------------------------------------------------------------- |
| 85 | +# Trigger power meter reading every second |
| 86 | +# ---------------------------------------------------------------------------------------------------- |
| 87 | +time: |
| 88 | + - platform: sntp |
| 89 | + on_time: |
| 90 | + - seconds: /1 |
| 91 | + then: |
| 92 | + - if: |
| 93 | + condition: |
| 94 | + - lambda: return id(power_meter_activated) != 0; |
| 95 | + then: |
| 96 | + - script.execute: power_meter_source |
0 commit comments