Force update of sensor every x minutes

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.

Thank you for your fast reply.

I belive it is an entity to the integration ‘trafikverket_train’ https://www.home-assistant.io/integrations/trafikverket_train/

Got to study that a bit

Thx for pointing me in some direction :slight_smile:

What are you trying to do? My automation is only applicable to the issue R5fan was pointing out.

I’m trying to make my trainstop-entities to update more often when they get closer to departure time. It’s quite annoying when you get information that the train is delayed after it is supposed to leave.

It’s specially important for my wife, who could chose to take the bus instead but it departs 1 minute before the train is departing.

I’d just add an update button in the ui for sometehing like that, keep in mind that it might take a moment for the data to refresh. Using the service above will update it. Keep in mind HA will suppress state changes. So if the state of the sensor does not change, you wont see it update after running that service.

Thank you petro. That might be why I thought I had an issue with it.

@petro I tried what you suggested here, but that doesn’t work for me: the integration entity is not updated. Any advice?

My integration entity:

{
  "entry_id": "ae7[...]5bd",
  "version": 1,
  "minor_version": 1,
  "domain": "integration",
  "title": "wled_energy",
  "data": {},
  "options": {
    "name": "wled_energy",
    "source": "sensor.wled_power",
    "method": "trapezoidal",
    "round": 6.0,
    "unit_time": "h",
    "unit_prefix": "k"
  },
  "pref_disable_new_entities": false,
  "pref_disable_polling": false,
  "source": "user",
  "unique_id": null,
  "disabled_by": null
}

My automation to force an update:

- id: '171[...]620'
  alias: "WLED energy: force update every min"
  trigger:
  - platform: state
    entity_id:
    - sensor.wled_energy
    for:
      hours: 0
      minutes: 1
      seconds: 0
  condition: []
  action:
  - service: homeassistant.update_entity
    metadata: {}
    data: {}
    target:
      entity_id: sensor.wled_energy
  mode: single

I even tried this trigger for the automation, but that doesn’t change anything:

...
  trigger:
  - platform: time_pattern
    minutes: /1
...

The result: when wled_power is constant, wled_energy is not updated:

Bonus question: will the recent “New state timestamp State.last_reported” change anything regarding this issue?

That’s how HA works. No updates to the value, you won’t see the state change. Calling update entity won’t work because the value is still the same for the power entity.

There are changes that are coming to adjust this behavior. I don’t know when they will be released.

1 Like

Hmm ok, I’m confused because I thought you were replying with a workaround for this behavior in your comment. But I guess I didn’t understand correctly what/who you were replying to!

Thank you for the quick reply. :heart:

Hi Petro, I’m very interested in the changes you are referring to. Is there a pull request or something about this so I can track the PR ?

otiel linked it in their posts bonus question

I\m now at 2024.7.4 and still there doesn’t seem to be a way to force state update that actually works. Home Assistant Core Integration: Update entity does nothing for me although I do know for certain that the state has changed cause I changed it myself manually using a mobile App. Only after about 5 minutes delay does the state value get updated in HA. The Integration I’m talking about is Netatmo.

Turn on debug logging and see if the update is getting new values