Update item state based on thing status?

Is it possible to update an item (A dummy switch), based on a thing’s state? I have a TV that the switch wont update if its turned off manually. The TV goes offline when off. Doesn’t appear I can do this with the NGRE.


Ok, so it’s just not possible through the NGRE.


rule    "Update LG TV State" 
	Thing "lgwebos:WebOSTV:baba0f95-2726-b14b-a908-fba3fce6297c" changed
	or System started
	var thingStatusInfo = getThingStatusInfo("lgwebos:WebOSTV:baba0f95-2726-b14b-a908-fba3fce6297c")
	if ((thingStatusInfo !== null) && (thingStatusInfo.getStatus().toString() == "ONLINE")) {
		logInfo("LG TV is: " + thingStatusInfo.getStatus().toString())
	else {
		logInfo("LG TV is: " +thingStatusInfo.getStatus().toString())


is creating this error:

2020-04-24 12:29:26.710 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Update LG TV State': index=1, size=1

You are missing the subpackage in your log…

You can definitely do this with scripted automation and I think I have posted examples. Here’s one…

You can do it with the UI rule editor too.

This should be possible from PaperUI using the “a thing changes status” trigger. It’s definitely possible using text based NGRE rules (e.g. .py files under $OH_CONF/automation).

I admit though that I’ve not created a Rule with “a thing changes status” trigger in PaperUI so that might be one of the broken triggers. But that should be the same as your Rules DSL trigger in post 4.

And I don’t think you would need to call thingStatusInfo except for the fact that it has a System started trigger. The receivedEvent implicit variable should be there when the Rule is triggered by the Channel.

I might consider a different approach. If you are interacting with this TV through a network, which is what I would assume, you could use the Network binding to control an “online” Switch. Then you can use that Switch with visibility on your sitemap to just hide those controls that are not valid when the TV is OFF. No need to deal with the Channels directly in that case which makes everything a bit more straight forward.

You don’t have the option to send a state change to an item in the ngre, that I could find…

  1. “When…” The Channel changes to OFFLINE

  1. “then…” send command to your Item

Repeat the two steps above for OFFLINE and OFF.

Or you can write it in JavaScript (or Python or any other supported and installed language).

  1. trigger the same as above only don’t fill in the Status, leave that blank. \

  2. Choose the “execute a given script” action

if(event.event == "OFFLINE") {
    events.postUpdate("LG_TV0_Power", "OFF");
else if(event.event == "ONLINE") {
    events.postUpdate("LG_TV0_Power", "ON");

What you don’t have though is a System started trigger.

Now since this works, I’d like to take it a step further. Is there a way to disable the switch, only in the off position?

No option to change an item’s State under #2

Can send a command, but not what im trying to accomplish

Sorry Rich, I didn’t scroll all the way down… :stuck_out_tongue_winking_eye:

What do you mean by “disable the switch”? You can hide the Item on your sitemap so based on it’s or some other Item’s state a read only Text element or nothing is shown when ON and a Switch element is shown when it’s ON.

Beyond that, there is no way to disable an Item. It’s there or it’s not.

But, essentially…If a device is off, and cannot be turned back on through the system, only manually…It would be nice to disable the switch on the UI…Not hide it, because it is still a visual aid to see that the TV is off

Text item=TV_Control visibility[TV_Status!=ON]
Switch item=TV_Control visibility[TV_Status==ON]

When the TV is offline and not controllable you see only the read only Text element.
When the TV is online and controllable, you see only the Switch Item and can control the TV.

This is how you disable a switch in sitemaps.

Alternatively, present the switch in asitemap, but disable autoupdate on the Item. If a linked channel never reports “ON”, you can poke at the UI switch all you like but it will not remain ON.

Thanks for the insight guys…