Updating a Sitemap Text Value with a Rule?[SOLVED]

I’ve created and Item:

Number LG_TV0_VolLevelDummy

I’ve created a Rule:

rule "VolumeUpDown"
when Item LG_TV0_VolDummy received command
then
    //LG_TV0_Toast.sendCommand(receivedCommand.toString)
    switch receivedCommand{
        case 0: LG_TV0_VolumeDown.sendCommand(ON)
        case 1: LG_TV0_VolumeUp.sendCommand(ON)
    }
    var vol = 100*LG_TV0_Volume.state as DecimalType
    postUpdate(LG_TV0_VolLevelDummy, vol)
    LG_TV0_Toast.sendCommand(vol.toString)//LG_TV0_Volume.state.toString)
end

and a Sitemap with this entry:

Text item=LG_TV0_VolLevelDummy label="Vol [%.0f]"

I can confirm that the vol variable updates but it’s not being updated in the sitemap unless I physically refresh the browser.

Any ideas?

Which UI (ClassicUI, BasicUI, HABpanel)? I think I may have noticed this in ClassicUI… have you tried using sendCommand instead of postUpdate?

@5iver BasicUI. I haven’t tried sendCommand; I can try report back.

I just tested this and it was properly refreshing the UI with the new value. I see you’ve edited your rule… maybe take it a bit further:

rule "VolumeUpDown"
when
    Item LG_TV0_VolDummy received command
then
    //LG_TV0_Toast.sendCommand(receivedCommand.toString)
    switch receivedCommand{
        case 0: LG_TV0_VolumeDown.sendCommand(ON)
        case 1: LG_TV0_VolumeUp.sendCommand(ON)
    }
    val vol = 100*(LG_TV0_Volume.state as DecimalType)
    LG_TV0_VolLevelDummy.postUpdate(vol)
    LG_TV0_Toast.sendCommand(vol)//LG_TV0_Volume.state.toString)
end

postUpdate requires the arguments to be strings, so you could also try postUpdate("LG_TV0_VolLevelDummy",vol.toString). I’m surprised your rule actually worked at all, but you said the item was updating. Did you notice any errors in the log? The postUpdate method is a little more forgiving. Here’s a good thread with more info:

1 Like

LG_TV0_VolLevelDummy.postUpdate(vol.toString)

This did the trick. Thanks for the help and the link to the documentation.