-
-
Save wildekek/4e19fb049eb7cea3a35fe801e3ed8f57 to your computer and use it in GitHub Desktop.
# Creates Home Assistant Power and Energy sensors for APSystems ECU-C | |
# Copy this file to /homeassistant/packages/ecu.yaml | |
# Add the following lines to the /homeassistant/configuration.yaml: | |
# homeassistant: | |
# packages: | |
# system: !include packages/ecu.yaml | |
# Update the IP (192.168.0.6) to the address your ECU runs at | |
# Update the ECUID (215000015509) to your ECUID. You can find this on the main webpage of the ECU | |
rest: | |
# Fetch power data | |
# This data is generated by measuring the CT clamps. | |
- resource: "http://192.168.0.6/index.php/hidden/set_get_app_info_json" | |
method: POST | |
scan_interval: 300 | |
payload: '{"Command_Id": "53","APS": "ASK","Command": "1","Version": "1.1","ECUID": "215000015509"}' | |
sensor: | |
- name: Solar Power Produced L1 | |
unique_id: solar_power_produced_l1 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: '{{ value_json["meter_data"]["power1"][-1]["powerA"] / 1000}}' | |
- name: Solar Power Produced L2 | |
unique_id: solar_power_produced_l2 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: '{{ value_json["meter_data"]["power1"][-1]["powerB"] / 1000 }}' | |
- name: Solar Power Produced L3 | |
unique_id: solar_power_produced_l3 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: '{{ value_json["meter_data"]["power1"][-1]["powerC"] / 1000 }}' | |
- name: Grid Power Produced L1 | |
unique_id: grid_power_produced_l1 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: >- | |
{% set power = value_json["meter_data"]["power2"][-1]["powerA"] / 1000 %} | |
{% if power < 0 %} | |
{{ power * -1 }} | |
{% else %} | |
0 | |
{% endif %} | |
- name: Grid Power Produced L2 | |
unique_id: grid_power_produced_l2 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: >- | |
{% set power = value_json["meter_data"]["power2"][-1]["powerB"] / 1000 %} | |
{% if power < 0 %} | |
{{ power * -1 }} | |
{% else %} | |
0 | |
{% endif %} | |
- name: Grid Power Produced L3 | |
unique_id: grid_power_produced_l3 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: >- | |
{% set power = value_json["meter_data"]["power2"][-1]["powerC"] / 1000 %} | |
{% if power < 0 %} | |
{{ power * -1 }} | |
{% else %} | |
0 | |
{% endif %} | |
- name: Grid Power Consumed L1 | |
unique_id: grid_power_consumed_l1 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: >- | |
{% set power = value_json["meter_data"]["power2"][-1]["powerA"] / 1000 %} | |
{% if power > 0 %} | |
{{ power }} | |
{% else %} | |
0 | |
{% endif %} | |
- name: Grid Power Consumed L2 | |
unique_id: grid_power_consumed_l2 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: >- | |
{% set power = value_json["meter_data"]["power2"][-1]["powerB"] / 1000 %} | |
{% if power > 0 %} | |
{{ power }} | |
{% else %} | |
0 | |
{% endif %} | |
- name: Grid Power Consumed L3 | |
unique_id: grid_power_consumed_l3 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: >- | |
{% set power = value_json["meter_data"]["power2"][-1]["powerC"] / 1000 %} | |
{% if power > 0 %} | |
{{ power }} | |
{% else %} | |
0 | |
{% endif %} | |
- name: Domestic Power Consumed L1 | |
unique_id: domestic_power_consumed_l1 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: '{{ (value_json["meter_data"]["power1"][-1]["powerA"] + value_json["meter_data"]["power2"][-1]["powerA"]) / 1000 }}' | |
- name: Domestic Power Consumed L2 | |
unique_id: domestic_power_consumed_l2 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: '{{ (value_json["meter_data"]["power1"][-1]["powerB"] + value_json["meter_data"]["power2"][-1]["powerB"]) / 1000 }}' | |
- name: Domestic Power Consumed L3 | |
unique_id: domestic_power_consumed_l3 | |
unit_of_measurement: kW | |
state_class: measurement | |
device_class: power | |
value_template: '{{ (value_json["meter_data"]["power1"][-1]["powerC"] + value_json["meter_data"]["power2"][-1]["powerC"]) / 1000 }}' | |
# Fetch energy data | |
# This data is generated by measuring the CT clamps. | |
scrape: | |
- resource: http://192.168.0.6/index.php/display/historical_data/meter_lifetime_energy/ | |
scan_interval: 300 | |
sensor: | |
- name: Solar Energy | |
unique_id: solar_energy | |
unit_of_measurement: kWh | |
device_class: energy | |
state_class: total | |
select: "div.table-responsive > table > tbody > tr:nth-of-type(1) > td:nth-of-type(3)" | |
value_template: '{{ value| float | round(3) }}' | |
- name: Grid Energy | |
unique_id: grid_energy | |
unit_of_measurement: kWh | |
device_class: energy | |
state_class: total | |
select: "div.table-responsive > table > tbody > tr:nth-of-type(2) > td:nth-of-type(3)" | |
value_template: '{{ value| float | round(3) }}' | |
template: | |
sensor: | |
# We need the inverted Grid Energy to feed the Grid Production meter | |
- name: "Grid Energy Inverted" | |
unique_id: grid_energy_inverted | |
state_class: total | |
device_class: energy | |
unit_of_measurement: "kWh" | |
state: "{{ states('sensor.grid_energy') | float * -1 }}" | |
utility_meter: | |
solar_energy_produced: | |
name: "Solar Energy Produced" | |
unique_id: solar_energy_produced | |
source: sensor.solar_energy | |
delta_values: false | |
net_consumption: false | |
periodically_resetting: false | |
grid_energy_consumed: | |
name: "Grid Energy Consumed" | |
unique_id: grid_energy_consumed | |
source: sensor.grid_energy | |
delta_values: false | |
net_consumption: false | |
periodically_resetting: false | |
grid_energy_produced: | |
name: "Grid Energy Produced" | |
unique_id: grid_energy_produced | |
source: sensor.grid_energy_inverted | |
delta_values: false | |
net_consumption: false | |
periodically_resetting: false | |
sensor: | |
# Calculate total power values | |
- platform: min_max | |
name: Solar Power Produced | |
unique_id: solar_power_produced | |
round_digits: 3 | |
type: sum | |
entity_ids: | |
- sensor.solar_power_produced_l1 | |
- sensor.solar_power_produced_l2 | |
- sensor.solar_power_produced_l3 | |
- platform: min_max | |
name: Grid Power Produced | |
unique_id: grid_power_produced | |
round_digits: 3 | |
type: sum | |
entity_ids: | |
- sensor.grid_power_produced_l1 | |
- sensor.grid_power_produced_l2 | |
- sensor.grid_power_produced_l3 | |
- platform: min_max | |
name: Grid Power Consumed | |
unique_id: grid_power_consumed | |
round_digits: 3 | |
type: sum | |
entity_ids: | |
- sensor.grid_power_consumed_l1 | |
- sensor.grid_power_consumed_l2 | |
- sensor.grid_power_consumed_l3 | |
- platform: min_max | |
name: Domestic Power Consumed | |
unique_id: domestic_power_consumed | |
round_digits: 3 | |
type: sum | |
entity_ids: | |
- sensor.domestic_power_consumed_l1 | |
- sensor.domestic_power_consumed_l2 | |
- sensor.domestic_power_consumed_l3 |
I would like to get 3 sensors using Energy Dashboard.
Here are the entities you're looking for:
- Solar production
solar_energy_produced
- imported energy
grid_energy_consumed
- Exported energy
grid_energy_produced
With your work, how to configure that ? I've tried using sensors:
- PV energy daily
- Import energy daily
- Export energy daily
But i get no datas for imported/exported energy after one hour...and a error message :
sensor.export_energy_daily (unavailable)
sensor.import_energy_daily (unavailable)
That's because these sensors do not exist in my yaml. No idea how you got to those names.
OK,
Maybe a problem with my configuration.yaml...
Is this correct ?
`#renvoi vers sensors
sensor: !include sensors.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
#renvoi vers packages (ECU-C)
homeassistant:
packages:
system: !include packages/ecu.yaml`
I can see sensors in developpement tools but i can't select them on my energy dashboard..
So.... it works?
Keep in mind that:
- The scrape interval is 300s, so you'll only have data available after 5 mins. (the ECU only updates this data every 5 mins: ¯_(ツ)_/¯ .
- These sensors will only be available after a restart of HA.
You're not giving me a lot to go on there buddy. That said, I don't think data is 'gone' but was just acquired at a later point in time. Probably Home Assistant was unable to reach the ECU for some reason. I would not worry about it too much tbh.
Hello,
I have followed all the steps provided, however, I still see zero production despite another consumption tracking module indicating overproduction. I specifically need the status "sensor.solar_energy_produced". The version of the add-on "APSystems ECU-R" I am using is v1.4.1.
Could you please assist me with this?
Thank you in advance.
Edit : After uninstall / reinstall its work now
Thank you for this code @wildekek . It works perfectly :-)
Hey @wildekek, I would like to suggest one additional feature that will add the "Imported/Exported" sensor to Home Assistant replicating the values you get in the APSystems app. That would be the grey line in the screenshot below:
We can get these values from this URL: 'http:///index.php/meter/old_meter_power_graph'
To create this new sensor would only require adding the code below to the existing ecu.yaml
# Update the IP (192.168.0.6) to the address your ECU runs at
- platform: rest
name: "Import Export Power" # Grid Import is (+) / Export is (-)
unique_id: import_export_power
device_class: power
state_class: measurement
unit_of_measurement: W
resource: http://192.168.0.6/index.php/meter/old_meter_power_graph
scan_interval: 300
value_template: >
{% if value_json is defined %}
{{ value_json.power2[-1].powerA }}
{% else %}
{{ "None" }}
{% endif %}
Please, let me know what you think. And congratulations again for the great work.
Hello, as there is a clamp at the counter, which entity corresponds to consumption or instant injection? I need to recover this value. Thanks for the work
Bonjour,
Avant de commencer l'intégration je voudrais savoir si vous avez eu des coupures pour être obliger de redémarrer l'ECU_C ?
Merci
Hi ! thanks for this job !
I would like to get 3 sensors using Energy Dashboard.
With your work, how to configure that ?
I've tried using sensors:
But i get no datas for imported/exported energy after one hour...and a error message :
sensor.export_energy_daily (unavailable)
sensor.import_energy_daily (unavailable)