I have Shelly EM monitoring:
Channel 1: Solar Production
Channel 2: House’s consumption
The energy panel though requests the following parameters:
1)PV generation energy
2)Returned to Grid energy
3)Consumed from Grid energy
In my case, Shelly’s channel 1 is equal to (1). For (2) and (3) I need to calculate them.
If Shelly.Power.Channel1 > Shelly.Power.Channel2, that means I generate more power than I consume hence the excessive energy goes all to grid.
If Shelly.Power.Channel2 > Shelly.Power.Channel1, that means I consume more power than I generate hence subtracting Channel2-Channel1 gives the energy drew from the Grid.
So far here is what I have setup.
template:
- sensor:
- name: "Exported_Energy"
unique_id: "Exported_Energy"
unit_of_measurement: "W"
device_class: power
state_class: measurement
state: >-
{% if states('sensor.shellyem_244cab419c34_channel_1_power')|float(0) - states('sensor.shellyem_244cab419c34_channel_2_power')|float(0) > 0 %}
{{ states('sensor.shellyem_244cab419c34_channel_1_power')|float(0) - states('sensor.shellyem_244cab419c34_channel_2_power')|float(0) }}
{% else %}
{{ (states('0.0') | float(0)) |round(3) }}
{% endif %}
- sensor:
- name: "Grid Consumption"
unique_id: "Grid_Consumption"
unit_of_measurement: "W"
device_class: power
state_class: measurement
state: >-
{% if states('sensor.shellyem_244cab419c34_channel_2_power')|float(0) - states('sensor.shellyem_244cab419c34_channel_1_power')|float(0) > 0 %}
{{ states('sensor.shellyem_244cab419c34_channel_2_power')|float(0) - states('sensor.shellyem_244cab419c34_channel_1_power')|float(0) }}
{% else %}
{{ (states('0.0') | float(0)) |round(3) }}
{% endif %}
- sensor:
- name: "Grid_Exported_Energy1"
unique_id: "Grid_Exported_Energy1"
state: "{{ '%0.2f'|format(states('sensor.Avg_Exported_Energy')|float / 1000 * (now().hour + now().minute/60)) }} "
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
- name: "Grid_Consumed_Energy1"
unique_id: "Grid_Consumed_Energy1"
state: "{{ '%0.2f'|format(states('sensor.Avg_Consumed_Energy')|float / 1000 * (now().hour + now().minute/60)) }} "
unit_of_measurement: "kWh"
device_class: energy
state_class: total_increasing
sensor:
- platform: average
name: 'Avg_Exported_Energy'
unique_id: "Avg_Exported_Energy"
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
entities: sensor.Exported_Energy
- platform: average
name: 'Avg_Exported_Energy_5_Min'
unique_id: "Avg_Exported_Energy_5_Min"
duration:
minutes: 5
entities: sensor.Exported_Energy
- platform: average
name: 'Avg_Consumed_Energy'
unique_id: "Avg_Consumed_Energy"
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
entities: sensor.Grid_Consumption
- platform: average
name: 'Avg_Consumed_Energy_5_Min'
unique_id: "Avg_Consumed_Energy_5_Min"
duration:
minutes: 5
entities: sensor.Grid_Consumption
Maybe someone could help because above setup doesn’t work well. It turns out above config has some fault.
Here is what I get in the energy setup screen: