Energy Management in Home Assistant

Yes, I use Envoy and participated in the beta. You need to create some additional sensors for ‘real time’ consumption and export.

    solar_export_value:
      friendly_name: Solar Export Value
      icon_template: mdi:solar-panel
      unit_of_measurement: "W"
      device_class: power
      value_template: >
        {% set value = (('%0.1f' | format(states('sensor.envoy_current_energy_production') | float - states('sensor.envoy_current_energy_consumption') | float)) | float) %}
        {% if value  <= 0 -%} 
          0
        {%- else -%}
          {{ value | round(2) }}
        {%- endif %}

    house_consumption_value:
      friendly_name: House Importing Value
      icon_template: mdi:transmission-tower
      unit_of_measurement: "W"
      device_class: power
      value_template: >
        {% set value = (('%0.1f' | format(states('sensor.envoy_current_energy_consumption') | float - states('sensor.envoy_current_energy_production') | float)) | float) %}
        {% if value  <= 0 -%} 
          0
        {%- else -%}
          {{ value | round(2) }}
        {%- endif %}

You then create two additional sensors using the Reimann Sum integration and point them to the sensors created above

- platform: integration
  source: sensor.house_consumption_value
  name: Imported Energy
  unit_prefix: k
  round: 2
  method: left

- platform: integration
  source: sensor.solar_export_value
  name: Exported Energy
  unit_prefix: k
  round: 2
  method: left

During the beta, one of these sensors had all the required values, but one didn’t. So I had to customise to add the device_class: energy, state_class: measurement and last_reset value.

Then set the imported energy sensor to be the ‘Grid Consumption’, exported exergy sensor as ‘Return to Grid’

edit: Added method: left to the integration sensors, since generation/consumption is considered spiky.

6 Likes

Dears,

Ia have a Shelly EM, I added the sensor to the grid configuration. But the graph is empty:

Any idea where is the problem?.

Thanbks,

Does this require specific type of devices? I’d like to track the energy usage of all my individual lights, TVs, etc.

It takes a while to start populating. Needs at least an hour’s worth of data - and I believe it updates at 12 minutes past the hour.

You have to enable it in your configuration, add energy:

Hi @tvds
I have a Saj inversor, and I found a workaround, but I’m facing a little issue.
My inversor goes on standby at night, and the sensor on HA becomes unavailable, so I used a workround:
I use a template sensor to count when the sensor isn’t “unavailable” or “unknow”:

sensor:
  - platform: template
    sensors:
      correct_energy_production:
        friendly_name: Energia Produzida Total
        icon_template: mdi:flash
        unit_of_measurement: kWh
        value_template: "{{ states('sensor.saj_today_yield')|float }}"
        availability_template: >
          {% if is_state("sensor.saj_today_yield", "unavailable") %}
            false
          {% elif is_state("sensor.saj_today_yield", "unknown") %}
            false
          {% else %}
            true
          {%- endif %}

and then I use a utility_meter for daily cicles:

utility_meter:
  total_production_daily:
    source: sensor.correct_energy_production
    cycle: daily

The only issue is at the end of solar production, the sensor get an astronic value, and I can’t figure out how to solve it. Example, today I produced 12.5KWh, and the utility_meter was counting good, until the inverter goes standby, after that, the sensor shows 74.9KWh as production today.

I also use influxdb and grafana, and the values coming from the sensor.saj_today_yield is correct
Screenshot 2021-08-05 at 01.12.24

Yeah. Same here.

Standard Solaredge integration, and although it has access to consumption, self consumption, generation, exported to grid etc it doesn’t show up.

I’ve created template sensors that replicate all those values again with state_class: measurement but still no luck as it appears template sensors aren’t supported.

+1 to emporia…

I’ve added that single solar source, but can’t seem to add the SolarEdge exported and imported power (using the standard SolarEdge cloud integration).

This looks amazing, thanks HA team!

Has anyone got this working with the fronius integration?

It looks like the sensors don’t have the required attributes.

Okay. Looks like the SolarEdge other sensors need last_reset added with the same value as the “date” attribute as they reset their values daily. I’ve managed to get them to show up by hard-coding their values, but not sure what code change would be required to update the integration.

state_class: measurement
last_reset: <set to the "date" atribute somehow>

2 Likes

Cheers mate. I’ve just added the code you supplied. All sensors seem to be working, and I’ve added them to the energy page, but grid consumption and return to grid are not showing anything. I’ve given it a few hours so something should be showing.

EDIT: Hmm, seems to have just updated. LOL. Now to check to make sure all the values are correct.

For what it’s worth I opened an issue to track this as my experience mirrors yours so far.

Thanks @dgaust, I got my sensors hooked up like yours are but I had to change the base sensors from sensor.envoy_current_energy_XXXXX to sensor.envoy_current_power_XXXXX. Would you please confirm that this is correct? I think they renamed those sensors for unit accuracy since they are reporting Watts (power) and not Watt-hours (energy).

      solar_export_value:
        friendly_name: Solar Export Value
        icon_template: mdi:solar-panel
        unit_of_measurement: "W"
        device_class: power
        value_template: >
          {% set value = (('%0.1f' | format(states('sensor.envoy_current_power_production') | float - states('sensor.envoy_current_power_consumption') | float)) | float) %}
          {% if value  <= 0 -%} 
            0
          {%- else -%}
            {{ value | round(2) }}
          {%- endif %}

      house_consumption_value:
        friendly_name: House Importing Value
        icon_template: mdi:transmission-tower
        unit_of_measurement: "W"
        device_class: power
        value_template: >
          {% set value = (('%0.1f' | format(states('sensor.envoy_current_power_consumption') | float - states('sensor.envoy_current_power_production') | float)) | float) %}
          {% if value  <= 0 -%} 
            0
          {%- else -%}
            {{ value | round(2) }}
          {%- endif %}

Unfortunately, I still don’t see the “Exported Energy” option I created to select from the “Return to grid” dropdown box. However, maybe I need that sensor to have some value besides zero on it (since it’s nighttime and I have not exported anything to the grid since creating the sensor)?
Hopefully, tomorrow I’ll see it pop up in there and I’ll be ready to go…

Yes, they may have changed, I’ve had the integration for almost a year now - so those entities have been around a while.

It looks ok to me - but you now need to create the other sensors and point them to these template sensors (yes, it’s a little complex).

- platform: integration
  source: sensor.house_consumption_value
  name: Imported Energy
  unit_prefix: k
  round: 2
  method: left

- platform: integration
  source: sensor.solar_export_value
  name: Exported Energy
  unit_prefix: k
  round: 2
  method: left

Restart, and then check to make sure those sensors exist - and also make sure they both have the following attributes

device_class: energy
state_class: measurement
last_reset: '2021-07-31T11:04:08.091669+00:00' (just any time in the past is fine)

If they’re not there, just use the customise entity option to add/change them.

They should then be available to select.

edit: Sorry, saw you’d created those integration sensors. So just double check the attributes are there.

2 Likes

Thanks @dgaust, I got it working with your help. It was that I needed to force the units as well (via customize). Once I did that I saw the “Exported Energy” option available.

I’m really getting excited about this new Energy Management in HA. I wonder if we’ll eventually be able to represent the array per-panel like the Enphase Enlighten app:
image

I’ve been wanting to do something like this with Home Assistant for so long… :smiley:

Is there a way to add a fixed daily cost to the energy cost calculation? I’m thinking like an extra entry field here:

8 Likes

Yet? Suggests this is possibly coming, is that correct?

How on earth did you get a Fronius to show up in here? I’ve spent the better part of the day trying to get either of the two integrations for them to show useful data

I didn’t do anything special, this is the code:

sensor:
  - platform: fronius
    resource: http://192.168.1.141
    scan_interval: 10
    monitored_conditions:
    - sensor_type: inverter
    - sensor_type: meter
    - sensor_type: power_flow

I’ll be checking tomorrow to see if the ones I’ve selected produce the correct values.