Force update of sensor every x minutes

I’m using Riemann sum integral integration for measuring electricity consumption. (from Watt to KiloWattHours), but the value of the integral is updating only if the input sensor (measuring in Watts) has changed. I would like to force updating the sum integral, so the value will change even if the power value is always the same.
Thank you.

If your source sensor is reading anything other than 0W the integration sensor should be increasing.
Else something is wrong !

Posting the yaml for your sensors and maybe a screen shot of the graph of both sensors may shed some light.

Thank you for your reply. Here is the configuration yaml and graphs of both sensors.

sensor:
  - platform: integration
    source: sensor.plug_pc_power
    name: plug_pc_spend
    unit_prefix: k
    round: 2

Screenshot from 2021-10-26 13-14-12
Screenshot from 2021-10-26 13-14-21

The integration knows the timestamp of the updates and properly calculates the area under the curve based on that information. Forcing an update will do nothing but add error into the calculation.

I would expect linear function if the plug_pc_power sensor has constant non-zero value. Instead of that the graph of plug_pc_spend looks like “stairs”

Because you use the wrong integration mode. Best is to use method: left.

I set method to left, but nothing has changed, and I think it should be less precise than trapezoid method. I don’t understand why plug_pc_spend is not updating lets say every minute if the plug_pc_power is constantly at 232 W. It is updating randomly instead.

What integration is plug_pc_spend ?

Yes this is normal. The integration will only update when it see’s state changes. It’s not seeing a state change so it does not update the kwh sensor.

Changing the method won’t help, they all act the same way: Update when a state change occurs.

And is there any way to do force update? I want correct result in every timestamp, not only on state change.

No, by default home assistant suppresses all updates when the state doesn’t change.

That is why I asked

If it are Tasmota or Zigbee2MQTT plugs, you can set

force_update: true

in the mqtt definition. For other integrations it is probably not possible.

Oh sorry, I was a little bit confused, because plug_pc_spend is riemann sum integral. plug_pc_power is zigbee2mqtt. I find a solution. In zigbee2mqtt web UI I set in a device max rep interval to 60 seconds, but your solution looks good. Can I ask where exactly I can set this setting? Thank you.

See :

I have a similar same problem with a template sensor. It tracks the power consumption of one of my pond pumps based on the state of a switch. But this pump will typically pump for days nonstop, and then the integration sensor based on the template power consumption will not update. I feel like this is a bug in the integration sensor, it shouldnt update if the referenced measurement is zero, but if its a constant non zero value, surely it should update?

I “solved” it now by changing the pumps calculated power consumption from 40W to 41W based on some random other entity, but thats a rather silly way. Does anyone have a better suggestion?

@R5fan found a solution to this bug?

No, I have not

it’s not a bug, it’s how home assistant is designed. You can make an automation to force an update on the integration entity.

This will force an update if the value hasn’t changed in 30 seconds.

- alias:  Update xyz when states haven't changed
  trigger:
  - platform: state
    entity_id: sensor.integration_entity
    for: "00:00:30"
  action:
  - service: homeassistant.update_entity
    target:
      entity_id: sensor.integration_entity
1 Like

This doesn’t help me at all. Even if I start i manually it won’t update an entity that I need to have updated.

Is it something I’m missing?

alias: test uppdatera åretåget
description: ""
trigger:
  - platform: state
    entity_id: sensor.ostersund_c_to_are
    for: "00:00:30"
action:
  - service: homeassistant.update_entity
    target:
      entity_id: sensor.ostersund_c_to_are
    data: {}
mode: single

is sensor.ostersund_c_to_are your integration entity? If no, then you need to use your integration entity.

nope, it just looks at your integration entity, if the state hasn’t changed for 30 seconds, it updates it.