|
| 1 | +# ---------------------------------------------------------------------------------------------------- |
| 2 | +# Sensor updated every second to give feedback in Home Assistant |
| 3 | +# ---------------------------------------------------------------------------------------------------- |
| 4 | + |
| 5 | +sensor: |
| 6 | + # Sensor showing the actual power consumption |
| 7 | + - id: real_power |
| 8 | + platform: template |
| 9 | + name: "Real Power" |
| 10 | + device_class: "power" |
| 11 | + unit_of_measurement: "W" |
| 12 | + update_interval: 1s |
| 13 | + |
| 14 | +# ---------------------------------------------------------------------------------------------------- |
| 15 | +# User interaction |
| 16 | +# ---------------------------------------------------------------------------------------------------- |
| 17 | + |
| 18 | +number: |
| 19 | + # Simulated load used for developement |
| 20 | + # It should be commented out for production |
| 21 | + - platform: template |
| 22 | + name: "Simulated Load" |
| 23 | + id: simulated_load_power |
| 24 | + optimistic: True |
| 25 | + restore_value: True |
| 26 | + mode: box |
| 27 | + min_value: -99999 |
| 28 | + max_value: 99999 |
| 29 | + initial_value: 0 |
| 30 | + unit_of_measurement: "W" |
| 31 | + step: 1 |
| 32 | + |
| 33 | +# ---------------------------------------------------------------------------------------------------- |
| 34 | +# Use http request component |
| 35 | +# ---------------------------------------------------------------------------------------------------- |
| 36 | + |
| 37 | +http_request: |
| 38 | + id: http_request_data |
| 39 | + useragent: esphome/device |
| 40 | + timeout: 10s |
| 41 | + |
| 42 | +# ---------------------------------------------------------------------------------------------------- |
| 43 | +# Define scripts for power collection |
| 44 | +# ---------------------------------------------------------------------------------------------------- |
| 45 | + |
| 46 | +script: |
| 47 | + # Fronius script gather power reports from inverter and update globals (real_power) |
| 48 | + # Information are provided as json. Power exchanged with the grid is names PowerReal_P_Sum |
| 49 | + # When this value is positive, energy is taken from the grid. |
| 50 | + # When this value is negative, energy is pushed to the grid. |
| 51 | + - id: power_meter_source |
| 52 | + mode: single |
| 53 | + then: |
| 54 | + - if: |
| 55 | + condition: |
| 56 | + wifi.connected: |
| 57 | + then: |
| 58 | + - http_request.get: |
| 59 | + url: http://${power_meter_ip_address}/solar_api/v1/GetMeterRealtimeData.cgi |
| 60 | + headers: |
| 61 | + Content-Type: application/json |
| 62 | + verify_ssl: False |
| 63 | + on_response: |
| 64 | + then: |
| 65 | + - lambda: |- |
| 66 | + json::parse_json(id(http_request_data).get_string(), [](JsonObject data) { |
| 67 | + id(real_power).publish_state(data["Body"]["Data"]["0"]["PowerReal_P_Sum"].as< float >() |
| 68 | + + id(simulated_load_power).state*id(triac_opening).state / 100 // Simulated load used for developement. It should be commented out for production. |
| 69 | + ); |
| 70 | + }); |
| 71 | +
|
| 72 | +time: |
| 73 | + - platform: sntp |
| 74 | + on_time: |
| 75 | + - seconds: /1 |
| 76 | + then: |
| 77 | + - if: |
| 78 | + condition: |
| 79 | + - lambda: return id(power_meter_activated) != 0; |
| 80 | + then: |
| 81 | + - script.execute: power_meter_source |
0 commit comments