Energy Management in Home Assistant

Template sensors are supported, as long as you use ‘modern’ template sensors and not ‘legacy’ style template sensors.

3 Likes

Thanks for the detailed reply… lol it would have been a touch easier if you had included the template: line above -sensor: though :slight_smile: once I figured out that it was bloody obvious :smiley:

For those that need a complete picture to set up the emoncms and the HA energy visualiser
step1: configure the emoncms integration so it gets all feeds:
step2: configure sensors as per the template below:
step3: set the attributes of the new sensors so they meet the data source requirements for the energy panel see 9/Aug update at the bottom of this post.
step4: configure the energy visualiser via:
http://hassio.lan:8123/energy
or
http://hassio.lan:8123/config/energy
step5: wait

This is what I have in my configuration:yaml for my local emoncms install (a pi v1)

sensor:
  - platform: emoncms
    api_key: < I use the read-only api key you get this from the http://192.168.1.x/feed/api >
    url: http://192.168.1.x/emoncms
    id: 1

template:
  - sensor:
      - name: Consumption
        state: "{{ states('sensor.emoncms_import_kwh') | float | round(2) }}"
        unit_of_measurement: "kWh"
        state_class: measurement
        device_class: energy
        attributes:         
          last_reset: '1970-01-01T00:00:00+00:00'
      - name: Return to Grid
        state: "{{ states('sensor.emoncms_use_kwh') | float | round(2) }}"
        unit_of_measurement: "kWh"
        state_class: measurement
        device_class: energy
        attributes:         
          last_reset: '1970-01-01T00:00:00+00:00'
      - name: Solar Production
        state: "{{ states('sensor.emoncms_solar_kwh') | float | round(2) }}"
        unit_of_measurement: "kWh"
        state_class: measurement
        device_class: energy
        attributes:         
          last_reset: '1970-01-01T00:00:00+00:00'

If you have multiple platforms in your sensor config, make sure you aren’t silly like me and you don’t copy-paste into the wrong part of your configuration.yaml

The last step (once you restart) is to go into you home assistant - developer tools - states page
http://hassio.lan:8123/developer-tools/state (for me)

select each of the 3 new entities:
sensor.consumption
sensor.return_to_grid
sensor.solar-production

and carefully paste the text below into each of these in the “Set State Attributes” box:
last_reset: ‘1970-01-01T00:00:00+00:00’
last_reset_value_template: ‘1970-01-01T00:00:00+00:00’

Make sure you hit SET STATE each time because without doing that it will not show up to be selected in the energy configuration wizard.

a big thankyou to:
@mnestor
@Tockers
@wyx087

If I need to make any further changes, I will incorporate them here so us part-time Home-Asisstant users find it easy to implement the new energy view.

edit: updated 9/Aug to add this to each sensor, as it seems to get lost after a reboot or something?

        attributes:         
          last_reset: '1970-01-01T00:00:00+00:00'
4 Likes

My utility_meter sensors don’t show up in energy either.

Not sure if it’s completely appropriate to post this here but I noticed in the Forecast.Solar Integration there is no way or selecting options for my solar panel / inverter configuration.

I have 6.6kW of solar panels but a 5kW invertor (limited by government regulation) so my solar generation follows a different pattern to if it was 5kW of panels and 5kW invertor, since I can produce more energy during low light conditions compared to having only 5kW of panels, yet my maximum is limited to 5kW.

Any ideas how to work around this? Perhaps I need to email the developer of Forecast.Solar…

1 Like

It looks like it’s because they are missing the device_class.

They work for me now. I converted my legacy template sensors to the new format.

Here is a newbie instruction for getting Enphase Envoy setup in the new Energy feature of 2021.8

Open up configuration.yaml

template:
  - sensor:
        name: Grid Export Power
        state_class: measurement
        icon: mdi:solar-panel
        unit_of_measurement: W
        device_class: power
        state: >
            {{ [0, states('sensor.envoy_serialnumber_current_power_production') | int - states('sensor.envoy_serialnumber_current_power_consumption') | int ] | max }}

  - sensor:
        name: Grid Import Power
        state_class: measurement
        icon: mdi:transmission-tower
        unit_of_measurement: W
        device_class: power
        state: >
            {{ [0, states('sensor.envoy_serialnumber_current_power_consumption') | int - states('sensor.envoy_serialnumber_current_power_production') | int ] | max }}

sensor:
  - platform: integration
    name: Grid Export Energy
    source: sensor.grid_export_power
    unit_prefix: k
    unit_time: h

  - platform: integration
    name: Grid Import Energy
    source: sensor.grid_import_power
    unit_prefix: k
    unit_time: h
3 Likes

Would like to know this too Dave - same situation (in Melbourne). I still need to work out what to input for declination and azimuth also.

The rounding was a hangover for another template I had that displayed the current status of import/export in kW rather than plain watts.

I just never removed it when I derived these particular templates from that one.

inst_energy_difference:
      friendly_name: Instant Energy Difference
      icon_template: >
        {% set value = ('%0.1f' | format(states('sensor.envoy_current_energy_production') | float - states('sensor.envoy_current_energy_consumption') | float)) | float %}
        {% if value > 0 -%} 
            mdi:solar-panel
        {%- elif value < 0 -%}
            mdi:transmission-tower
        {%- else -%}
            mdi:power-off
        {%- endif %}
      friendly_name_template: >
        {% set value = ('%0.1f' | format(states('sensor.envoy_current_energy_production') | float - states('sensor.envoy_current_energy_consumption') | float)) | float %}
        {% if value > 0 -%} 
            Currently Exporting
        {%- elif value < 0 -%}
            Currently Importing
        {%- else -%}
            Balanced
        {%- endif %}
      unit_of_measurement: "kW"
      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) / 1000 %}
        {% if value  < 0 -%} 
          {{ (value * -1) | round(2) }}
        {%- else -%}
          {{ value | round(2) }}
        {%- endif %}
1 Like

I’ve just sent the Forecast.Solar devs an email explaining the situation and asking for the added functionality… We can only hope.

Hi Knut Kohl,

I live in Australia where we have government regulations regarding the maximum inverter size for residential properties, however the limit on solar panel capacity is higher. This means that we can have 6.6kW of panels but only a 5kW inverter. The benefit of this setup is that during the lower light periods of the day (morning and evening) we generate more power than we would if the panels and inverter were both 5kW, however we are still limited to a 5kW max output peak.

This creates an odd graph of solar output throughout the day compared to a simple 5kW / 5kW system. We basically generate that of a 6.6kW system up until it reaches 5kW, then plateaus at 5kW until the afternoon, then ramps down as if it was a 6.6kW system (from below 5kW).

Would it be possible to have such settings added to Forecast.Solar to accommodate this type of configuration? As I say, this is the same for all Australian residents with full capacity solar systems, so there is a huge user base. I just don’t think many people would think about this when setting up Forecast.Solar.

It would be great if you could consider this added functionality.

Regards,

Dave M

2 Likes

Have anyone configured necessary energy sensors via REST sensors?.

I have an interface with my inverter from which I retrieve that with REST sensors (consumption, production, balance, injection, etc.)

Is it possible?

Is it useful in Melbourne anyway? The home page says they have no data for most of Australia yet, definitely including Melbourne.

The Fronius integration polls the inverter with a REST API and publishes each measurement as an entity. You could write a custom integration to do something similar or maybe use the RESTful sensor integration depending on the format.

If you already have the data published to PVOutput you could also get it back from there using the PVOutput integration although obviously that’s a cloud dependency you might wish to avoid.

The Fronius integration doesn’t seem to provide great energy figures (limitation of the inverter), only power, so I use some template sensors and the integration and utility_meter integrations to get the data in a useful format.

Just scrolled through all the posts in this thread and don’t think this was mentioned:

I have a 2kWp PV installation connected to the grid and use an automation with my 2kW water heater to get advantage of Portugal’s 15 minute net metering.
The result is, each 15 minute period, I use some energy from the grid but the net energy is negative (more injection than consumption).

Is there a way to see use the net energy values in the Energy management instead of the “instant” energy integrations?
If not, is this in the table for a future improvement?

Anyway, congratulations to the devs for this amazing feature.

For me it doesnt graph at all,

I did add the devices in energy,
left it for 14 hours still nothing…

Is there somewhere a energy log ?
so i can see if it’s reporting any activity.

regards

how did u convert them?

I managed to get them in the list, but after 14 hours no graph :frowning:

Nice!

I have a lot’s of esphome devices reporting their power usage (pzem004t for the whole house mains, various sockets with power metering hardware) and lot’s of switches with static loads I just added a template_sensor reporting the power usage (for example a light switch with a 8w light bulb will show a Assumed Power of 8w in home assistant when the switch is on.

Thing is that I’m not able to add the last group to home assistant energy management.

It’s only possible for devices which have power monitoring capabilities.

For me that’s very annoying because I loose a lot’s of information like all the power consumption for lightning.

How can I overcome this and feed home assistant all the information I have about my power usage?

Hi all,

Taking a look at the Energy panel, once I have configured Consumption, Solar Production and injection entities (via rest sensor converted to template sensor), I get these values which seem something strange:

Taking a look to the graphs, I think there is something wrong. My consumption sensor shows the “current” consumption (updated each 5 seconds) so I do not know if this is exactly what Energy entity needs.

In the other hand, Solar production is the same. My sensor shows the “current production”, updated each 5 seconds. It has no sense to have negative values in solar production or 300% consumed in solar energy KPI in the right column.

What is going wrong?

I find it all weid, still not showing up anything.

@frenck
is there a file containing that information about the new energy ?
i think it’s not showing up because i tested with devices previously as Watt instead of kWh… maybe it messed up.
It got updated yesterday to kWh output but still no graph after 14hours

regards

after updating to the last core-update i get this message all the time i visit /energy or refresh

Logger: frontend.js.latest.202108040
Source: components/system_log/__init__.py:190
First occurred: 16:20:13 (1 occurrences)
Last logged: 16:20:13

https://MY-DNS:8123/lovelace/0:0:0 Uncaught

// UPDATE: solved, did not show up after full reboot.

or something like a shelly or sonoff POW R2 depending on HVAC power requirements