Integration - Riemann useless for fixed power sensor creation

I’m just seting up my energy dasboard. For many of devices, where power reading is not available directly, I use PowerCalc add-on to create virtual sensors. Among them I have few 'always on devices and for them such sensor is based on fixed assumed (or measured) power consumption (due to lack of better data). Then I use Riemann Integration to create sensors for total energy consumption. Unfortunatelly it seems not to work as intended. Seems Riemann integration only calculates output when the input value change, disregarding time flow. So until value of input sensor gets somehow changed intgration based sensors shows unchanged value (or even do not initiate for this matter, when used for the first time). It is fine for even slowly changing values, as sooner or later it will update, but for fixed one it just does not work. I was thinking about using timer to add/substract some meaningless value to input sensor, but this require to duplicate all of them and is not too elegant solution. Is there any reasonable solution to this issue? Or do I miss something in configuration?

You can also let powercalc create the riemann sensor, it can do that out of the box (just set create_energy_sensor to true). It will create the riemann sensor with integration method left which is important to have the sensor calculate correctly even when the value does not change.
You can also have a look into daily energy sensor, which seems to fit your needs even better.

Hope this helps.

This is what I did for most of my sensors and it works for 40+ devices managed by PowerCalc… Though I think it does not work for sensors created outside of addon… Here is the the relevant sample of code I use for problematic sensors:

powercalc:
  create_energy_sensors: true
  create_utility_meters: true

template:
  - sensor:
      # this sensor takes % of UPS load and recalculates it to consumed power
      # at this moment UPS is disconnected, so as default it uses average load I observed in the past
      # this makes sensor reporting constant power, without state updates
      - name: My IT Rack
        unique_id: my_it_rack
        state: >-
          {{ states('sensor.cyberpower_ups_load') | float (default=10) * 1350 / 100 }}
        unit_of_measurement: "W"
        device_class: power

sensor:
  # This sensor takes  ouput of above one and uses it as input for integral calculation
  # here the problems comes as it does not recalculate over time
  # BTW exact same config work fine for frequently changing state input sensors
  - platform: integration
    source: sensor.my_it_rack
    name: my_it_rack_energy
    unique_id: my_it_rack_energy
    unit_prefix: k
    round: 4

So as these sensors are created outside of PowerCalc, it does not create corresponding energy sensors, as you described.
I use daily energy sensor for few devices and indeed it works fine. I think the problem is that here I use generic sensor to calculate power and it, obviously, does not play with PowerCalc. It is also specific condition, as my UPS failed and is under RMA, so sensor generates constant value… Hope to get it fixed within few days
Though, to be honest, I’d not blame your addon here, it is great piece of code! I’d rather expect Riemann Integration to calculate value properly over time, without waiting for input sensor state change…

The riemann sensors only react on state changes of the underlying power sensor.

When you create a template sensor and it’s value is static the state will never actually change in the state machine and the riemann sensor not calculate a new kWh value. I don’t think you can force template sensors to do a state change.

The power sensors you create with powercalc force a state change every now and than force_update_frequency. The exact purpose of this is to make the riemann sensor do it’s thing even if the value of the power sensor stays static.
That being said you can just feed a template in the fixed -> power configuration setting, so you can just replace your template sensor with a powercalc power sensor.

2 Likes

Thanks fo rexplanation and advise! I ended up with creation of temporary static sensor with PowerCalc and it works perfectly!
Now, when I get my UPS back, I’ll need to revert to previous working setup…

1 Like

Hi. I had the same situation (fixed power template sensor not updating until it’s toggled off & on).

While I’m aware of PowerCalc, I just needed to cover one heater and didn’t want to overkill it.

So, I adjusted my template sensor with fixed power to update every minute, based on whether the current minute is an even number or not:

      - name: "Calefactor Power"
        unique_id: "calefactor_power"
        unit_of_measurement: "W"
        state: >
            {% if is_state('switch.calefactor', 'on') and (now().minute%2 == 1) %}788
            {% elif is_state('switch.calefactor', 'on') %}787
            {% else %}0{% endif %}
        state_class: measurement
        device_class: power

With this, I can then have a Riemann (Left) Helper that will provide kWh, use that in Energy Dashboard, which generates a Cost sensor, which I then use in a Utility Meter to have a real-time daily cost (since Energy’s cost sensor randomly resets to 0 or doesn’t reset at midnight). I find this whole thing weird but that’s a different topic.

Anyway, silly but it works, especially just for one or few.
Cheers

1 Like