Skip to content

Commit a9dc227

Browse files
authored
feat: Improve energy counter theorical to detect when energy is not consumed
2 parents e1e7b3e + d1a6f0e commit a9dc227

13 files changed

+132
-44
lines changed

docs/en/energy_counter_theorical.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ packages:
1616
url: https://github.com/XavierBerger/Solar-Router-for-ESPHome/
1717
file: solar_router/energy_counter_theorical.yaml
1818
```
19+
20+
!!! question "What happen if theorical energy diverted is not consumed?"
21+
If the water in boiler is already hot, the regulation grow up to 100% but no energy will be consumed.
22+
If the power meter used is providing the energy consumed, the energy counter detects this situation and reports 0 energy diverted.
23+
If energy consumed is not reported, the theorical energy consumed will be calculated at its maximum.
24+
1925
Then you have to define the **load power** in Home Assistant `Control` interface. The power entered has to reflect the power of the element plugged on solar router.
2026

2127
![alt text](images/SolarRouterEnergyCounterTheoricalConfiguration.png)

docs/fr/energy_counter_theorical.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@ La quantité d'énergie détournée est calculée en fonction de la puissance de
1010

1111
Pour utiliser ce compteur, ajoutez les lignes suivantes à votre fichier de configuration.
1212

13-
1413
```yaml
1514
packages:
1615
counter:
1716
url: https://github.com/XavierBerger/Solar-Router-for-ESPHome/
1817
file: solar_router/energy_counter_theorical.yaml
1918
```
19+
!!! question "Que se passe-t-il si l'énergie théorique déviée n'est pas consommée ?"
20+
Si l'eau dans la chaudière est déjà chaude, la régulation passe à 100 %, mais aucune énergie ne sera consommée.
21+
Si le compteur de puissance utilisé fournit l'énergie consommée, le compteur d'énergie détecte la situation et rapporte une consommation nulle.
22+
Si la consommation d'énergie n'est pas reportée, la consommation d'énergie théorique sera calculée à son maximum.
23+
2024
Ensuite, vous devez définir la puissance de charge (**Load power**)S dans l'interface `Control` de Home Assistant. La puissance saisie doit refléter la puissance de l'élément branché sur le routeur solaire.
2125

2226
![texte alternatif](images/SolarRouterEnergyCounterTheoricalConfiguration.png)

docs/images/packages.drawio.png

11.3 KB
Loading

esp8266-standalone_on_off.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ substitutions:
3838
# Power meter source -----------------------------------------------------------
3939
# Define ip address of Power Meter (Fronius Inverter)
4040
main_power_sensor: "sensor.smart_meter_ts_100a_1_puissance_reelle"
41+
consumption_sensor: "sensor.solarnet_power_load_consumed"
4142

4243
# LEDs -------------------------------------------------------------------------
4344
# Green LED is reflecting regulation status

solar_router/energy_counter_theorical.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ script:
2020
mode: single
2121
then:
2222
- lambda: |-
23-
id(therorical_energy_diverted).publish_state(id(load_power).state*id(regulator_opening).state / 100);
23+
double diverted_energy = id(load_power).state*id(regulator_opening).state / 100;
24+
if (id(consumption).state >= diverted_energy or isnan(id(consumption).state))
25+
{
26+
// Therorical energy diverted is consumed (or we don't know the consumption)
27+
id(therorical_energy_diverted).publish_state(diverted_energy);
28+
}
29+
else
30+
{
31+
// Therorical energy diverted is not consumed
32+
id(therorical_energy_diverted).publish_state(0.0);
33+
}
34+
2435
2536
# Sensor showing the actual energy diverted consumption
2637
sensor:

solar_router/power_meter_common.yaml

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,25 @@ globals:
1010
- id: power_meter_activated
1111
type: int
1212
initial_value: ${power_meter_activated_at_start}
13-
restore_value: True
13+
restore_value: True
14+
15+
16+
# ----------------------------------------------------------------------------------------------------
17+
# Sensor updated every second to give feedback in Home Assistant
18+
# ----------------------------------------------------------------------------------------------------
19+
sensor:
20+
# Sensor showing the actual power consumption
21+
- id: real_power
22+
platform: template
23+
name: "Real Power"
24+
device_class: "power"
25+
unit_of_measurement: "W"
26+
update_interval: 1s
27+
28+
# Sensor showing the actual power consumption
29+
- id: consumption
30+
platform: template
31+
name: "Consumption"
32+
device_class: "power"
33+
unit_of_measurement: "W"
34+
update_interval: 1s

solar_router/power_meter_fronius.yaml

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22

33
esphome:
44
min_version: 2024.11.1
5-
# ----------------------------------------------------------------------------------------------------
6-
# Sensor updated every second to give feedback in Home Assistant
7-
# ----------------------------------------------------------------------------------------------------
8-
sensor:
9-
# Sensor showing the actual power consumption
10-
- id: real_power
11-
platform: template
12-
name: "Real Power"
13-
device_class: "power"
14-
unit_of_measurement: "W"
15-
update_interval: 1s
165

176
# ----------------------------------------------------------------------------------------------------
187
# Use http request component
@@ -54,7 +43,7 @@ script:
5443
id(real_power).publish_state(NAN);
5544
} else {
5645
bool parse_success = json::parse_json(body, [](JsonObject root) -> bool {
57-
if (!root.containsKey("Body") || !root["Body"]["Data"]["0"].containsKey("PowerReal_P_Sum")) {
46+
if (!root.containsKey("Body")) {
5847
ESP_LOGW("custom", "Invalid JSON structure");
5948
return false;
6049
}
@@ -72,6 +61,42 @@ script:
7261
- lambda: |-
7362
ESP_LOGW("custom", "HTTP Request failed or timeout occurred");
7463
id(real_power).publish_state(NAN);
64+
- http_request.get:
65+
url: http://${power_meter_ip_address}/solar_api/v1/GetPowerFlowRealtimeData.fcgi
66+
headers:
67+
Content-Type: application/json
68+
capture_response: true
69+
max_response_buffer_size: 4096
70+
on_response:
71+
then:
72+
- lambda: |-
73+
if (response->status_code != 200) {
74+
ESP_LOGW("custom", "HTTP Request failed with status: %d", response->status_code);
75+
id(consumption).publish_state(NAN);
76+
} else {
77+
bool parse_success = json::parse_json(body, [](JsonObject root) -> bool {
78+
if (!root.containsKey("Body")) {
79+
ESP_LOGW("custom", "Invalid JSON structure");
80+
id(consumption).publish_state(NAN);
81+
return false;
82+
}
83+
id(consumption).publish_state(
84+
root["Body"]["Data"]["Site"]["P_Grid"].as<float>()
85+
+ root["Body"]["Data"]["Site"]["P_PV"].as<float>()
86+
);
87+
return true;
88+
});
89+
90+
if (!parse_success) {
91+
ESP_LOGW("custom", "JSON Parsing failed");
92+
id(consumption).publish_state(NAN);
93+
}
94+
}
95+
on_error:
96+
then:
97+
- lambda: |-
98+
ESP_LOGW("custom", "HTTP Request failed or timeout occurred");
99+
id(consumption).publish_state(NAN);
75100
time:
76101
- platform: sntp
77102
on_time:

solar_router/power_meter_home_assistant.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
# ----------------------------------------------------------------------------------------------------
66

77
sensor:
8-
# Sensor showing the actual power consumption
8+
# Sensor showing the actual power exchange
99
- platform: homeassistant
1010
id: real_power
1111
entity_id: ${main_power_sensor}
1212
internal: False
1313
name: "Real Power"
1414
device_class: "power"
1515
unit_of_measurement: "W"
16+
17+
# Sensor showing the actual consumption
18+
- platform: homeassistant
19+
id: consumption
20+
entity_id: ${consumption_sensor}
21+
internal: False
22+
name: "Consumption"
23+
device_class: "power"
24+
unit_of_measurement: "W"

solar_router/power_meter_proxy_client.yaml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,6 @@
22

33
esphome:
44
min_version: 2024.11.1
5-
# ----------------------------------------------------------------------------------------------------
6-
# Sensor updated every second to give feedback in Home Assistant
7-
# ----------------------------------------------------------------------------------------------------
8-
sensor:
9-
# Sensor showing the actual power consumption
10-
- id: real_power
11-
platform: template
12-
name: "Real Power"
13-
device_class: "power"
14-
unit_of_measurement: "W"
15-
update_interval: 1s
165

176
# ----------------------------------------------------------------------------------------------------
187
# Use http request component
@@ -68,7 +57,36 @@ script:
6857
- lambda: |-
6958
ESP_LOGW("custom", "HTTP Request failed or timeout occurred");
7059
id(real_power).publish_state(NAN);
60+
- http_request.get:
61+
url: http://${power_meter_ip_address}/sensor/consumption
62+
capture_response: true
63+
max_response_buffer_size: 4096
64+
on_response:
65+
then:
66+
- lambda: |-
67+
if (response->status_code != 200) {
68+
ESP_LOGW("custom", "HTTP Request failed with status: %d", response->status_code);
69+
id(consumption).publish_state(NAN);
70+
} else {
71+
bool parse_success = json::parse_json(body, [](JsonObject root) -> bool {
72+
if (!root.containsKey("value")) {
73+
ESP_LOGW("custom", "Invalid JSON structure");
74+
return false;
75+
}
76+
id(consumption).publish_state(root["value"].as< float >());
77+
return true;
78+
});
7179
80+
if (!parse_success) {
81+
ESP_LOGW("custom", "JSON Parsing failed");
82+
id(consumption).publish_state(NAN);
83+
}
84+
}
85+
on_error:
86+
then:
87+
- lambda: |-
88+
ESP_LOGW("custom", "HTTP Request failed or timeout occurred");
89+
id(consumption).publish_state(NAN);
7290
time:
7391
- platform: sntp
7492
on_time:

solar_router/power_meter_shelly_em.yaml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
<<: !include power_meter_common.yaml
22

3-
# ----------------------------------------------------------------------------------------------------
4-
# Sensor updated every second to give feedback in Home Assistant
5-
# ----------------------------------------------------------------------------------------------------
6-
7-
sensor:
8-
# Sensor showing the actual power consumption
9-
- id: real_power
10-
platform: template
11-
name: "Real Power"
12-
device_class: "power"
13-
unit_of_measurement: "W"
14-
update_interval: 1s
15-
163
# ----------------------------------------------------------------------------------------------------
174
# Use http request component
185
# ----------------------------------------------------------------------------------------------------

0 commit comments

Comments
 (0)