thanks for the quick feedback! I will provide the feedback as you proposed. Thanks & kind regards, red
In this thread I have personally linked the right document many times, last time was this: Home Energy Management in 2021.8 - #205 by alexdelprete
Salutations,
I am new to this reality and I am finding it difficult to insert the meters in the “energy management” screen.
In my home system I have 2 SDM120 energy meters, one for solar production and the other for home consumption, where I also view grid feeds.
When the value is positive it means that I import energy from enel when it is negative I export.
I created thanks to your previous posts this in the file sensor.yaml
#contatore di scambio consumo/immissione
- platform: rest
name: energy monitor total house watts
resource: http://x.x.mywire.org:8080/api/last/SDM1.2
value_template: '{{ value_json.PowerL1 }}'
#unit_of_measurement: 'W'
#device_class: energy
force_update: true
# divide i valori del contatore di scambio in 2 sensori
# negativo=immissione e positivo=consumo
- platform: template
sensors:
# Negative values only - if not negative return 0, otherwise provide "Return to Grid" Value
house_energy_negative:
unique_id: house_energy_negative
unit_of_measurement: 'W'
device_class: energy
value_template: >
{% if states('sensor.energy_monitor_total_house_watts') | int <= 0 %}
{{ (states('sensor.energy_monitor_total_house_watts') | int) | abs }}
{% endif %}
# Positve values only - if negative, return 0, otherwise provide "Power from Grid" Value
house_energy_positive:
unique_id: house_energy_positive
unit_of_measurement: 'W'
device_class: energy
value_template: >
{% if states('sensor.energy_monitor_total_house_watts') | int >= 0 %}
{{ states('sensor.energy_monitor_total_house_watts') }}
{% endif %}
# Add all the watts used by house (which goes negative) with total solar generated to get total house used metric
house_energy_used_total:
unique_id: house_energy_total
unit_of_measurement: 'W'
value_template: "{{ states('sensor.energy_monitor_total_house_watts') | float + states('sensor.energy_monitor_total_solar_watts') | float }}"
- platform: integration
source: sensor.house_energy_negative
name: energy_spent_energy_backtogrid
unit_prefix: k
round: 2
- platform: integration
source: sensor.house_energy_positive
name: energy_spent_energy_positive
unit_prefix: k
round: 2
and this in the file configuration.yaml
template:
- sensor:
name: "Solar Energy Power"
unit_of_measurement: 'Wh'
state: >
{% if states('sensor.solar_power')|float >= 0 %}
{{ states('sensor.solar_power') }}
{% else %}
0
{% endif %}
device_class: energy
state_class: measurement
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
- sensor:
- name: "Import Energy Power"
unit_of_measurement: 'Wh'
state: >
{{ (states("sensor.import_power") | float) | round(2) }}
device_class: energy
state_class: measurement
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
- sensor:
- name: "house energy positive import"
unit_of_measurement: 'Wh'
state: >
{{ (states("sensor.house_energy_positive") | float) | round(2) }}
device_class: energy
attributes:
last_reset_value_template: "{{ '1970-01-01T00:00:00+00:00' }}"
state_class: measurement
# attributes:
# last_reset: '1970-01-01T00:00:00+00:00'
- sensor:
- name: "house energy negative export"
unit_of_measurement: 'Wh'
state: >
{{ (states("sensor.house_energy_negative") | float) | round(2) }}
device_class: energy
attributes:
last_reset_value_template: "{{ '1970-01-01T00:00:00+00:00' }}"
state_class: measurement
# attributes:
# last_reset: '1970-01-01T00:00:00+00:00'
what could be the problem?
I made several attempts but nothing
Thank you
You have everything wrong. You confuse power with energy, example of one of your sensors:
template:
- sensor:
name: "Solar Energy Power"
unit_of_measurement: 'Wh'
state: >
{% if states('sensor.solar_power')|float >= 0 %}
{{ states('sensor.solar_power') }}
{% else %}
0
{% endif %}
device_class: energy
state_class: measurement
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
If the sensor is a POWER MEASUREMENT, you can’t use it in a template just defining device class=energy, doesn’t work that way. If instead it is energy, and the sensor represents is the inverter’s production (I can’t see it in your post), since you used state_class: measurement, I suppose that is NOT an accumulated value, or is it? If it’s an accumulated value, and it’s ALWAYS increasing, you should use total or total_increasing.
Plus, like I wrote here:
In order for the sensors to appear in the energy integration they must have the following attributes (last_reset is not needed anymore, except in very specific cases):
- device_class set to energy
- state_class set to either: measurement or total or total_increasing
But the root cause of your problems, at least from what I read in your post, is that you didn’t understand the underlying difference between power measurement sensors and sensors that measure the amount of energy produced during a time interval.
Check this post: Home Energy Management in 2021.8 - #137 by alexdelprete
Look at the drawing above: power is the water flow rate, energy is the amount of water in the bucket. Power is an instantaneous measured value, Energy is calculated taking into account how much power in time. Time is the key variable to understand the difference among the two.
You need to fix the theory first, then you can implement things through HA. If instead you got the theory correct, I apologize, but reading your post my impression is that there was some confusion.
Anyway, let me know and I’ll try to help as much as I can.
maybe I’m getting confused because I don’t understand the theory well.
The value I take via API and Power but when I enter device_class: power I get error in “energy management”
Exactly what I thought. The energy dashboard needs energy sensors, you seem to have only power sensors.
You need 3 energy sensors: production (total energy produced by the inverter), export (total energy sent to the network), import (total energy imported from the networ).
So, first of all, how do you pull data from the inverter? The energy meters you mentioned should provide both power and energy values, if you send me a link to the documents of the meter I can check what is available.
These are the data I recover via api
{"SDM1.1":{"Timestamp":"2022-03-18T00:07:22.929682037+01:00","Unix":1647558442,"ApparentPower":0.000000,"Cosphi":0.000000,"CosphiL1":-0.085188,"CosphiL2":0.000000,"CosphiL3":0.000000,"CurrentL1":0.303976,"CurrentL2":0.000000,"CurrentL3":0.000000,"Export":23.976000,"ExportL1":0.000000,"ExportL2":0.000000,"ExportL3":0.000000,"Frequency":49.971092,"Import":3259.903076,"ImportL1":0.000000,"ImportL2":0.000000,"ImportL3":0.000000,"ImportPower":5.867935,"Power":0.000000,"PowerL1":-5.864012,"PowerL2":0.000000,"PowerL3":0.000000,"ReactivePower":0.000000,"Sum":3283.878906,"SumL1":0.000000,"SumL2":0.000000,"SumL3":0.000000,"THD":0.000000,"THDL1":0.000000,"THDL2":0.000000,"THDL3":0.000000,"VoltageL1":228.322714,"VoltageL2":0.000000,"VoltageL3":0.000000},"SDM1.2":{"Timestamp":"2022-03-18T00:07:19.868014867+01:00","Unix":1647558439,"ApparentPower":0.000000,"Cosphi":0.000000,"CosphiL1":0.614866,"CosphiL2":0.000000,"CosphiL3":0.000000,"CurrentL1":0.785925,"CurrentL2":0.000000,"CurrentL3":0.000000,"Export":2326.107910,"ExportL1":0.000000,"ExportL2":0.000000,"ExportL3":0.000000,"Frequency":49.975738,"Import":1650.955547,"ImportL1":0.000000,"ImportL2":0.000000,"ImportL3":0.000000,"ImportPower":157.153774,"Power":0.000000,"PowerL1":89.822294,"PowerL2":0.000000,"PowerL3":0.000000,"ReactivePower":0.000000,"Sum":3977.063574,"SumL1":0.000000,"SumL2":0.000000,"SumL3":0.000000,"THD":0.000000,"THDL1":0.000000,"THDL2":0.000000,"THDL3":0.000000,"VoltageL1":228.366558,"VoltageL2":0.000000,"VoltageL3":0.000000}}
Ok, so I found the manual here.
In the manual I found this:
From the display description, I can see that this meter is an import/export meter and it has a modbus interface. So basically it can give you the total imported energy, the total exported energy, and then it calculates a total in different modes: import+export, import-export, only import. By default it does import+export.
From what I read, you can never have a negative value like you wrote in your post, you have 2 different total counters that only increase, one for imported energy and one for exported energy.
So, for the SDM120 connected to the production (contatore di produzione in italia), you should use the IMPORT ACTIVE ENERGY value as the PRODUCTION energy sensor in HA. It is in kWh, it’s a total_increasing type.
For the SDM120 connected to the exchange (contatore di scambio):
- use IMPORT ACTIVE ENERGY value as the IMPORT energy sensor in HA. It is in kWh, it’s a total_increasing type
- use EXPORT ACTIVE ENERGY value as the EXPORT energy sensor in HA. It is in kWh, it’s a total_increasing type
So in the end you will have 3 sensors in HA:
- sensor.sdm120prod.energy_production - Total Increasing Counter for Energy produced by the inverter
- sensor.sdm120scambio.energy_import - Total Increasing Counter for Energy imported from the network (bought)
- sensor.sdm120scambio.energy_export - Total Increasing Counter for Energy exported to the network (sold)
In the JSON you sent me I see 2 objects, one for each SDM120, the first one looks like the SDM120prod, and the second seems like the SDM120scambio. I put a note in square brackets to map for you the values you need to pull for the HA sensors:
{
"SDM1.1": {
"Timestamp": "2022-03-18T00:07:22.929682037+01:00",
"Unix": 1647558442,
"ApparentPower": 0,
"Cosphi": 0,
"CosphiL1": -0.085188,
"CosphiL2": 0,
"CosphiL3": 0,
"CurrentL1": 0.303976,
"CurrentL2": 0,
"CurrentL3": 0,
"Export": 23.976,
"ExportL1": 0,
"ExportL2": 0,
"ExportL3": 0,
"Frequency": 49.971092,
"Import": 3259.903076, ------> [sensor.sdm120prod.energy_production]
"ImportL1": 0,
"ImportL2": 0,
"ImportL3": 0,
"ImportPower": 5.867935,
"Power": 0,
"PowerL1": -5.864012,
"PowerL2": 0,
"PowerL3": 0,
"ReactivePower": 0,
"Sum": 3283.878906,
"SumL1": 0,
"SumL2": 0,
"SumL3": 0,
"THD": 0,
"THDL1": 0,
"THDL2": 0,
"THDL3": 0,
"VoltageL1": 228.322714,
"VoltageL2": 0,
"VoltageL3": 0
},
"SDM1.2": {
"Timestamp": "2022-03-18T00:07:19.868014867+01:00",
"Unix": 1647558439,
"ApparentPower": 0,
"Cosphi": 0,
"CosphiL1": 0.614866,
"CosphiL2": 0,
"CosphiL3": 0,
"CurrentL1": 0.785925,
"CurrentL2": 0,
"CurrentL3": 0,
"Export": 2326.10791, ------> [sensor.sdm120scambio.energy_export]
"ExportL1": 0,
"ExportL2": 0,
"ExportL3": 0,
"Frequency": 49.975738,
"Import": 1650.955547, ------> [sensor.sdm120scambio.energy_import]
"ImportL1": 0,
"ImportL2": 0,
"ImportL3": 0,
"ImportPower": 157.153774,
"Power": 0,
"PowerL1": 89.822294,
"PowerL2": 0,
"PowerL3": 0,
"ReactivePower": 0,
"Sum": 3977.063574,
"SumL1": 0,
"SumL2": 0,
"SumL3": 0,
"THD": 0,
"THDL1": 0,
"THDL2": 0,
"THDL3": 0,
"VoltageL1": 228.366558,
"VoltageL2": 0,
"VoltageL3": 0
}
}
Once you have these 3 fundamental values, you can calculate TOTAL CONSUMPTION and TOTAL AUTOCONSUMPTION (autoconsumption is the energy produced and consumed locally):
- autoconsumption = production - export
- consumption = import + autoconsumption
Each of these energy sensors have to have the following attributes:
state_class: total_increasing
unit_of_measurement: kWh
device_class: energy
Here are a couple of my energy sensors:
Hope this helps, let me know.
Alessandro
Congratulations Alessandro you have made a fantastic explanation and also identifying what I had not told you yet, congratulations. In the afternoon I will do as you told me and let you know. Thank you
Please don’t laugh if I’m wrong (I’m a little inexperienced on the subject but I’m trying)
I entered the following data in the file sensor.yaml
- platform: rest
name: sdm120prod
resource: http://xx.mywire.org:8080/api/last/SDM1.1
value_template: '{{ value_json.Import }}'
unit_of_measurement: 'kWh'
device_class: energy
force_update: true
- platform: rest
name: sdm120scambio Import
resource: http://xx.mywire.org:8080/api/last/SDM1.2
value_template: '{{ value_json.Import }}'
unit_of_measurement: 'kWh'
device_class: energy
force_update: true
- platform: rest
name: sdm120scambio Export
resource: http://xx.mywire.org:8080/api/last/SDM1.2
value_template: '{{ value_json.Export }}'
unit_of_measurement: 'kWh'
device_class: energy
force_update: true
e questo nel file configuration.yaml
template:
- sensor:
name: "Sdm120prod Energy Production"
icon: mdi:solar-power
unit_of_measurement: 'kWh'
state: >
{% if states('sensor.solar_power')|float >= 0 %}
{{ states('sensor.solar_power') }}
{% else %}
0
{% endif %}
device_class: energy
state_class: total_increasing
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
- sensor:
name: "Sdm120scambio Energy Import"
icon: mdi:home-import-outline
unit_of_measurement: 'kWh'
state: >
{{ (states("sensor.sdm120scambio_import") | float) | round(2) }}
device_class: energy
state_class: total_increasing
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
- sensor:
name: "Sdm120scambio Energy Export"
icon: mdi:home-export-outline
unit_of_measurement: 'kWh'
state: >
{{ (states("sensor.sdm120scambio_export") | float) | round(2) }}
device_class: energy
state_class: total_increasing
attributes:
last_reset: '1970-01-01T00:00:00+00:00'
I did not understand this “utilizzare il valore IMPORT ACTIVE ENERGY come sensore di energia IMPORT in HA”
where should I enter it?
Thank you
First of all, remove the last_reset attribute from all the sensors, it’s not needed because your counters always increase and never reset.
Now that you have these 3 sensors defined, go into dev tools, and in the filter write sdm120 so you show only the three sensors related to sdm120, and do a screenshot for me, I want to check that everything’s ok. This is an example from my system:
If the sensors are ok with all correct attributes, you can go into the energy dashboard and feed it with the three sensors. They should be correctly recognised.
What are these two sensors?
Why is the energy production at 0?
I think you have mixed data, the old wrong sensors with the new ones. You need to clean up things.
Check in Dev Tools->Statistics Tab if there are some things to fix regarding sensors.
What was the problem?
I still don’t understand why you duplicated the sensors…
I was wrong to transcribe
I do not think I have duplicated the sensors, I think I did as you told me now I am sending you everything
in the sensor.yaml file I put this
- platform: rest
name: sdm120prod
resource: http://xx.mywire.org:8080/api/last/SDM1.1
value_template: '{{ value_json.Import }}'
unit_of_measurement: 'kWh'
device_class: energy
force_update: true
- platform: rest
name: sdm120scambio Import
resource: http://xx.mywire.org:8080/api/last/SDM1.2
value_template: '{{ value_json.Import }}'
unit_of_measurement: 'kWh'
device_class: energy
force_update: true
- platform: rest
name: sdm120scambio Export
resource: http://xx.mywire.org:8080/api/last/SDM1.2
value_template: '{{ value_json.Export }}'
unit_of_measurement: 'kWh'
device_class: energy
force_update: true
and in the configuration.yaml file this
template:
- sensor:
name: "Sdm120prod Energy Production"
icon: mdi:solar-power
unit_of_measurement: 'kWh'
state: >
{% if states('sensor.sdm120prod')|float >= 0 %}
{{ states('sensor.sdm120prod') }}
{% else %}
0
{% endif %}
device_class: energy
state_class: total_increasing
- sensor:
name: "Sdm120scambio Energy Import"
icon: mdi:home-import-outline
unit_of_measurement: 'kWh'
state: >
{{ (states("sensor.sdm120scambio_import") | float) | round(2) }}
device_class: energy
state_class: total_increasing
- sensor:
name: "Sdm120scambio Energy Export"
icon: mdi:home-export-outline
unit_of_measurement: 'kWh'
state: >
{{ (states("sensor.sdm120scambio_export") | float) | round(2) }}
device_class: energy
state_class: total_increasing
I don’t have other sensors in the files, for now the Energy screen is the following, but I think it needs to be updated.
This is an English-based forum, please.