#Weird behaviour from energy template sensor

8 messages · Page 1 of 1 (latest)

plain spire
#

Hi,

I've created a template that is supposed to collect what I'm paying for electricity with an hourly rate. I've got a sensor to give me the hourly price, this updates every fifth minute. The trouble is that I'm getting very weird values from this sensor. I suppose it has to do with the update interval, and that I am counting wrong somewhere, but not sure how.

- platform: template
  sensors:
    total_energy_cost_moving_rate:
      friendly_name: "Total Energy Cost Moving Rate"
      unit_of_measurement: "SEK"
      value_template: >
        {% set usage = states('sensor.frient_utility_meter_test') | float %}
        {% set moving_cost = states('sensor.nordpool_kwh_se3_sek_3_10_025') | float %}
        {% set cost = usage * moving_cost %}
        {{ cost | round(2) }}

The sole purpose with this sensor is to add it to a utility meter, so that I can calculate the daily cost from it.

See the image for output of a utility meter with this sensor as input. I would expect the value to be somewhere around 30 SEK.

I've also got an almost exact copy of this sensor, but with a set rate, as comparison. This works as expected, so the problem lies somewhere within the nordpool sensor reading. I've also attached an image of that sensors output (note that it updates every fifth minute, but the value only changes once an hour).

#

Should I use the riemann integral helper here in some way?

neat cosmos
#

You got the right idea. Because what you want is not the current usage level * current price, but the sum of all (usage in the last hour * price for the last hour). That's an integration problem.

plain spire
neat cosmos
#

Through the helpers tab in the UI. But first you need a template sensor that provides current price * consumption in the last x min, with x as small as possible.

plain spire
#

Alright, so:

  • template sensor with current price * hourly consumption
  • reimann integral helper
  • into a utility meter?
#

What would be the settings for the reimann helper?

neat cosmos
#

Try with the defaults? You really only have to tweak the method, but that depends on how the values from your input sensor behave.