Create virtual/simulated constant power meter

Hello all,
I would like to simulate the energy consumption of my permanently running devices (refrigerator, router, bridges, NAS, etc.) with a sensor. For this I created a sensor that has a constant power:

    current_power_router:
      friendly_name: "Power: Router"
      unit_of_measurement: "W"
      value_template: "{{12|float}}"

I want to convert this value to energy with “platform:integration”

  platform: integration
  source: sensor.current_power_router
  name: energy_spent_router
  unit_prefix: k
  round: 3 

and record it monthly and yearly with utility_meter.

monthly_energy_router:
  source: sensor.energy_spent_router
  cycle: monthly
yearly_energy_router:
  source: sensor.energy_spent_router
  cycle: yearly

However, both the integration sensor and the utility_meter show 0.000 kWh. For my other simulated sensors, which are calculated with depending on the on/off status, this procedure works. Unfortunately not for the constant values. Does the sensor have to send values to integration in intervals or where is my thinking error?

1 Like

Opening paragraph of the integration integration:

The integration sensors is updated upon changes of the source . Fast sampling source sensors provide better results.

Perhaps create a trigger-based template sensor that updates every minute (use sensor.time (docs) as your trigger) and slightly vary the amount:

{{ 12 + [0.01,-0.01,0]|random }}
3 Likes

Oh man, I totally missed that one. Thanks a lot!

I made an automation that updates the selected sensors every minute using Time pattern trigger and the service homeassistant.update_entity. :slight_smile:

But I am not sure if the interval (every minute) is enough or every 15 seconds would give more accurate values. Or is one value per minute enough for “platform:integration”?

For this constant value dummy sensor, it doesn’t matter. For real sensors, it depends on the way it measures.

For example, my house power sensor counts flashes of my electricity meter and reports that every minute. Over a short period of time and at low power draw, that can be quite inaccurate with a 60W minimum resolution, but integrated over time, it’s 100% accurate as it counts every Wh flash.

image
image

(this isn’t the integration sensor, but ESPHome’s total_daily_energy, a similar thing)

However, if you have a smart plug running a kettle that reports instantaneous power consumption, and the kettle boils in under a minute, there’s a chance that sampling every minute will miss the kettle’s energy usage altogether. In that situation, you need to consider the usage to select a suitable sampling frequency.