Skip to content

Commit

Permalink
feat: Improve energy counter theorical to detect when energy is not c…
Browse files Browse the repository at this point in the history
…onsumed
  • Loading branch information
XavierBerger authored Jan 30, 2025
2 parents e1e7b3e + d1a6f0e commit a9dc227
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 44 deletions.
6 changes: 6 additions & 0 deletions docs/en/energy_counter_theorical.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ packages:
url: https://github.com/XavierBerger/Solar-Router-for-ESPHome/
file: solar_router/energy_counter_theorical.yaml
```
!!! question "What happen if theorical energy diverted is not consumed?"
If the water in boiler is already hot, the regulation grow up to 100% but no energy will be consumed.
If the power meter used is providing the energy consumed, the energy counter detects this situation and reports 0 energy diverted.
If energy consumed is not reported, the theorical energy consumed will be calculated at its maximum.
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.

![alt text](images/SolarRouterEnergyCounterTheoricalConfiguration.png)
Expand Down
6 changes: 5 additions & 1 deletion docs/fr/energy_counter_theorical.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ La quantité d'énergie détournée est calculée en fonction de la puissance de

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


```yaml
packages:
counter:
url: https://github.com/XavierBerger/Solar-Router-for-ESPHome/
file: solar_router/energy_counter_theorical.yaml
```
!!! question "Que se passe-t-il si l'énergie théorique déviée n'est pas consommée ?"
Si l'eau dans la chaudière est déjà chaude, la régulation passe à 100 %, mais aucune énergie ne sera consommée.
Si le compteur de puissance utilisé fournit l'énergie consommée, le compteur d'énergie détecte la situation et rapporte une consommation nulle.
Si la consommation d'énergie n'est pas reportée, la consommation d'énergie théorique sera calculée à son maximum.
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.

![texte alternatif](images/SolarRouterEnergyCounterTheoricalConfiguration.png)
Expand Down
Binary file modified docs/images/packages.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions esp8266-standalone_on_off.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ substitutions:
# Power meter source -----------------------------------------------------------
# Define ip address of Power Meter (Fronius Inverter)
main_power_sensor: "sensor.smart_meter_ts_100a_1_puissance_reelle"
consumption_sensor: "sensor.solarnet_power_load_consumed"

# LEDs -------------------------------------------------------------------------
# Green LED is reflecting regulation status
Expand Down
13 changes: 12 additions & 1 deletion solar_router/energy_counter_theorical.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ script:
mode: single
then:
- lambda: |-
id(therorical_energy_diverted).publish_state(id(load_power).state*id(regulator_opening).state / 100);
double diverted_energy = id(load_power).state*id(regulator_opening).state / 100;
if (id(consumption).state >= diverted_energy or isnan(id(consumption).state))
{
// Therorical energy diverted is consumed (or we don't know the consumption)
id(therorical_energy_diverted).publish_state(diverted_energy);
}
else
{
// Therorical energy diverted is not consumed
id(therorical_energy_diverted).publish_state(0.0);
}
# Sensor showing the actual energy diverted consumption
sensor:
Expand Down
23 changes: 22 additions & 1 deletion solar_router/power_meter_common.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,25 @@ globals:
- id: power_meter_activated
type: int
initial_value: ${power_meter_activated_at_start}
restore_value: True
restore_value: True


# ----------------------------------------------------------------------------------------------------
# Sensor updated every second to give feedback in Home Assistant
# ----------------------------------------------------------------------------------------------------
sensor:
# Sensor showing the actual power consumption
- id: real_power
platform: template
name: "Real Power"
device_class: "power"
unit_of_measurement: "W"
update_interval: 1s

# Sensor showing the actual power consumption
- id: consumption
platform: template
name: "Consumption"
device_class: "power"
unit_of_measurement: "W"
update_interval: 1s
49 changes: 37 additions & 12 deletions solar_router/power_meter_fronius.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

esphome:
min_version: 2024.11.1
# ----------------------------------------------------------------------------------------------------
# Sensor updated every second to give feedback in Home Assistant
# ----------------------------------------------------------------------------------------------------
sensor:
# Sensor showing the actual power consumption
- id: real_power
platform: template
name: "Real Power"
device_class: "power"
unit_of_measurement: "W"
update_interval: 1s

# ----------------------------------------------------------------------------------------------------
# Use http request component
Expand Down Expand Up @@ -54,7 +43,7 @@ script:
id(real_power).publish_state(NAN);
} else {
bool parse_success = json::parse_json(body, [](JsonObject root) -> bool {
if (!root.containsKey("Body") || !root["Body"]["Data"]["0"].containsKey("PowerReal_P_Sum")) {
if (!root.containsKey("Body")) {
ESP_LOGW("custom", "Invalid JSON structure");
return false;
}
Expand All @@ -72,6 +61,42 @@ script:
- lambda: |-
ESP_LOGW("custom", "HTTP Request failed or timeout occurred");
id(real_power).publish_state(NAN);
- http_request.get:
url: http://${power_meter_ip_address}/solar_api/v1/GetPowerFlowRealtimeData.fcgi
headers:
Content-Type: application/json
capture_response: true
max_response_buffer_size: 4096
on_response:
then:
- lambda: |-
if (response->status_code != 200) {
ESP_LOGW("custom", "HTTP Request failed with status: %d", response->status_code);
id(consumption).publish_state(NAN);
} else {
bool parse_success = json::parse_json(body, [](JsonObject root) -> bool {
if (!root.containsKey("Body")) {
ESP_LOGW("custom", "Invalid JSON structure");
id(consumption).publish_state(NAN);
return false;
}
id(consumption).publish_state(
root["Body"]["Data"]["Site"]["P_Grid"].as<float>()
+ root["Body"]["Data"]["Site"]["P_PV"].as<float>()
);
return true;
});
if (!parse_success) {
ESP_LOGW("custom", "JSON Parsing failed");
id(consumption).publish_state(NAN);
}
}
on_error:
then:
- lambda: |-
ESP_LOGW("custom", "HTTP Request failed or timeout occurred");
id(consumption).publish_state(NAN);
time:
- platform: sntp
on_time:
Expand Down
11 changes: 10 additions & 1 deletion solar_router/power_meter_home_assistant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,20 @@
# ----------------------------------------------------------------------------------------------------

sensor:
# Sensor showing the actual power consumption
# Sensor showing the actual power exchange
- platform: homeassistant
id: real_power
entity_id: ${main_power_sensor}
internal: False
name: "Real Power"
device_class: "power"
unit_of_measurement: "W"

# Sensor showing the actual consumption
- platform: homeassistant
id: consumption
entity_id: ${consumption_sensor}
internal: False
name: "Consumption"
device_class: "power"
unit_of_measurement: "W"
40 changes: 29 additions & 11 deletions solar_router/power_meter_proxy_client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

esphome:
min_version: 2024.11.1
# ----------------------------------------------------------------------------------------------------
# Sensor updated every second to give feedback in Home Assistant
# ----------------------------------------------------------------------------------------------------
sensor:
# Sensor showing the actual power consumption
- id: real_power
platform: template
name: "Real Power"
device_class: "power"
unit_of_measurement: "W"
update_interval: 1s

# ----------------------------------------------------------------------------------------------------
# Use http request component
Expand Down Expand Up @@ -68,7 +57,36 @@ script:
- lambda: |-
ESP_LOGW("custom", "HTTP Request failed or timeout occurred");
id(real_power).publish_state(NAN);
- http_request.get:
url: http://${power_meter_ip_address}/sensor/consumption
capture_response: true
max_response_buffer_size: 4096
on_response:
then:
- lambda: |-
if (response->status_code != 200) {
ESP_LOGW("custom", "HTTP Request failed with status: %d", response->status_code);
id(consumption).publish_state(NAN);
} else {
bool parse_success = json::parse_json(body, [](JsonObject root) -> bool {
if (!root.containsKey("value")) {
ESP_LOGW("custom", "Invalid JSON structure");
return false;
}
id(consumption).publish_state(root["value"].as< float >());
return true;
});
if (!parse_success) {
ESP_LOGW("custom", "JSON Parsing failed");
id(consumption).publish_state(NAN);
}
}
on_error:
then:
- lambda: |-
ESP_LOGW("custom", "HTTP Request failed or timeout occurred");
id(consumption).publish_state(NAN);
time:
- platform: sntp
on_time:
Expand Down
13 changes: 0 additions & 13 deletions solar_router/power_meter_shelly_em.yaml
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
<<: !include power_meter_common.yaml

# ----------------------------------------------------------------------------------------------------
# Sensor updated every second to give feedback in Home Assistant
# ----------------------------------------------------------------------------------------------------

sensor:
# Sensor showing the actual power consumption
- id: real_power
platform: template
name: "Real Power"
device_class: "power"
unit_of_measurement: "W"
update_interval: 1s

# ----------------------------------------------------------------------------------------------------
# Use http request component
# ----------------------------------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions tools/compile_all_local_yaml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
for iloop in $(ls *.yaml | grep -v secrets | grep -v work_in_progress | grep -v proof-of-concept); do
echo
echo "#########################################"
echo Compiling $iloop
./tools/convert_to_local_source_for_dev.sh $iloop && esphome compile work_in_progress.yaml || exit 1
done
4 changes: 2 additions & 2 deletions wt32-eth01-power-meter-proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ logger:
# Enable Home Assistant API
api:
encryption:
key: !secret wt32_eth01_2_api_encryption_key
key: !secret wt32_eth01_api_encryption_key

# Enable over-the-air updates
ota:
- platform: esphome
password: !secret wt32_eth01_2_ota_password
password: !secret wt32_eth01_ota_password

# WiFi connection
# To activate WiFi :
Expand Down
4 changes: 2 additions & 2 deletions wt32-eth01-standalone_on_off.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ logger:
# Enable Home Assistant API
api:
encryption:
key: !secret wt32_eth01_2_api_encryption_key
key: !secret wt32_eth01_api_encryption_key

# Enable over-the-air updates
ota:
- platform: esphome
password: !secret wt32_eth01_2_ota_password
password: !secret wt32_eth01_ota_password

# WiFi connection
# To activate WiFi :
Expand Down

0 comments on commit a9dc227

Please sign in to comment.