Is it possible to add estimated power metering for devices without hardware metering? (Like in Athom Homey)

Tags: #<Tag:0x00007fc41aea08b8>

I’m migrating away from Athom Homey and to Home Assistant which is by far a more powerful and customizable platform. However in Homey, it is possible to add software based estimated power metering on the devices that doesn’t have built in power metering.

For instance for Sonos zones, Everspring dimmers without metering, etc. you have two custom settings on the device:

Power usage when off: 0
Power usage when on: 140

In the example above, an Everspring wall plug dimmer have a led strip connected which uses 140 watts when brightness is 100%.

That makes it possible to get a much more detailed picture of the current power consumption for all smart devices. A very clever function.

Is there a similar possibility in Home Assistant?

Yes but it’s not as simple.

Use the history statistics sensor to total how long your device has been on then use a template sensor to multiply that by the device’s power rating to get an estimate of the energy consumption.

1 Like

Hmm, okay. Thanks. Do you by any chance have some code examples on how to do this in real life?

I’ve done, or tried, something like this. It still might be a bit buggy or might need further tuning. But I think it might be a good way to start for you

Start by creating template sensors for current energy consumption

sensor:
- platform: template
  sensors:
# Energy Sensors (static)
      energy_electricity_lightbulb1_kwh:
        unit_of_measurement: "kWh"
        value_template: >-
          {% if is_state('light.lightbulb1', 'on') %}
            {{ (((((now() - states.light.lightbulb1.last_changed).seconds)/(60*60) | float) * (states.input_number.energy_electricity_lightbulb1.state | float)) / 1000 ) | round(3) }}
          {% else %}
            0
          {% endif %}

This snippet will use the time, that the lightbulb is on
(now() - states.light.lightbulb1.last_changed).seconds)/(60*60) | float) and multiply it with the energy consumption that is stored via an input number (states.input_number.energy_electricity_lightbulb1.state | float)

After you’ve created the sensors, you can add them to the utility meter in order to make use of the advanced features of this integration:

utility_meter:
  energy_electricity_daily_kwh:
    source: sensor.energy_electricity_lightbulb1_kwh
    cycle: daily

If you want to get more sophisticated, you can adjust the template sensor, by differentiating between on, off, standby, charging, different kind of brightness levels and so on.

1 Like

I do this with a tremplate sensor. I get the power values with a plug in power meter to measure the values when on and off:

monitor_power:
      unit_of_measurement: "W"
      device_class: power
      value_template: >-
        {% if is_state('media_player.monitor', 'on') %}
          72.0
        {% else %}
          0.5
        {% endif %}

and use Integration to generate a Kwh entity

- platform: integration
  source: sensor.monitor_power
  name: monitor_energy_spent
  unit_prefix: k
  round: 2

and that can be used with a utility meter

1 Like

Brilliant, guys! Thank you very much. Both of your examples was exactly what I needed to “get it” and have my energy metering a lot more precise.

I’m gonna create a lot of template sensors for my Magic Areas integration to easily see the power use of each room and globally.