How to refresh state of an item in a widget

I’ve built a custom widget for a smart plug that has a button to turn the plug on/off and includes on the button the current power consumption.
When the button is pressed to change the state, it takes a while before the power value is updated although I expect the value changes when the state changes.

    actionItem: =props.switch
    action: command
    actionCommand: TOGGLE
    text: >
      = "Current Power:" + " " 
      Math.floor((items[props.currentpower].state).split(' ')[0])
      + " Watts"
    textColor: green
    outline: true
    color: =items[props.switch].state=="OFF"?"gray":"blue"
    round: true
      display: flex
      flex-wrap: nowrap
      flex-direction: column
      justify-content: center
      align-items: center
      height: 100%
      width: 100%
      box-shadow: var(--f7-button-raised-box-shadow)
      --f7-button-hover-bg-color: rgba(var(--f7-theme-color-rgb), .1)
      --f7-button-bg-color: rgba(255,255,255, 1)

I’ve since used the marketplace toggle_widget which does the same thing as my custom widget but it has the same consideration in the delayed value updating.

You put your code on this forum with code fences.
The easiest way is type 3 ` (back ticks) top left hand of keyboard and then paste and then type another 3 back ticks.

In your log file you can review state changes of the relevant items.
Depending on your device the power consumption value is maybe not update immediately?

MainUI gets the Item events when the Item changes or is updated via the event stream. When an Item changed event comes over it updates all the visible widgets that use that Item. If the widget isn’t updating, that usually means either none of your Items are updating/changing because there is something wrong with the event stream, or the Item itself isn’t changing and therefore there is no event.

Thank you for the suggestion to look at the log.
It took 58 seconds from when the power-on action was indicated to when the power change event was signaled. Checking on the Kasa app, it changed almost immediately. Not particularly a problem if it is delayed by a minute - I was just curious.

If you use tp link binding, than you should look into the thing configuration, as there is a refresh parameter, that’s described in the documentation