postUpdate trigger command

I have a switch to start and stop my car heater

Switch VolvoHeater	"Car Heater"							<heating>	(gVolvo, gPCR, gPxb)	[ "Switchable" ]	{ exec=">[ON:voc heater start] >[OFF:voc heater stop]" }

I am also having a rule to get status from my car

rule VolvoStatus
Time cron "0 0/5 * * * ?" or
Item VolvoHeater changed or
Item VolvoEngine changed or
Item VolvoLock changed



var String vocjson = executeCommandLine("voc print" , 360000)

	VolvoLocation.postUpdate(transform("JSONPATH","$.position.latitude", vocjson) + "," +transform("JSONPATH","$.position.longitude", vocjson))
	VolvoLocationTS.postUpdate(transform("JSONPATH","$.position.timestamp", vocjson).replace("+00:00",""))
	VolvoHeater.postUpdate(transform("JSONPATH","$.heater.status", vocjson).replace("off","OFF").replace("onOther","ON").replace("on","ON"))
	VolvoEngine.postUpdate(transform("JSONPATH","$.engineRunning", vocjson).replace("false","OFF").replace("true","ON"))
	VolvoLock.postUpdate(transform("JSONPATH","$.carLocked", vocjson).replace("false","OFF").replace("true","ON"))
	VolvoDoorFL.postUpdate(transform("JSONPATH","$.doors.frontLeftDoorOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))
	VolvoDoorFR.postUpdate(transform("JSONPATH","$.doors.frontRightDoorOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))
	VolvoDoorRL.postUpdate(transform("JSONPATH","$.doors.rearLeftDoorOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))
	VolvoDoorRR.postUpdate(transform("JSONPATH","$.doors.rearRightDoorOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))
	VolvoHood.postUpdate(transform("JSONPATH","$.doors.hoodOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))
	VolvoTailGate.postUpdate(transform("JSONPATH","$.doors.tailgateOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))
	VolvoWindowFL.postUpdate(transform("JSONPATH","$.windows.frontLeftWindowOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))
	VolvoWindowFR.postUpdate(transform("JSONPATH","$.windows.frontRightWindowOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))
	VolvoWindowRL.postUpdate(transform("JSONPATH","$.windows.rearLeftWindowOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))
	VolvoWindowRR.postUpdate(transform("JSONPATH","$.windows.rearRightWindowOpen", vocjson).replace("false","CLOSED").replace("true","OPEN"))

But even if i use postUpdate still the switch execute the command.


Guess a workaround could be to remove the channel/exec from the switch statement and instead use a rule that trigger on RECEIVED command , like:


Switch VolvoHeater "Car Heater" <heating> (gVolvo, gPCR, gPxb) [ "Switchable" ]


rule "VolvoHeater"
       Item VolvoHeater received command
	if (receivedCommand == ON) {
		executeCommandLine("voc heater start")
	} else if (receivedCommand == OFF) {
		executeCommandLine("voc heater stop")

This will not trigger on postUpdate

This behaviour started in 2.4.
I have to use the workaround.


That’s odd, people usually have trouble getting the v1 exec binding to do anything, not with it doing too much!

That does look correct to me, executing voc only for commands.
Note that autoupdate will have effect - shortly after the command, the Item will get updated. That shouldn’t matter here.

May we see event log showing the sequence?

I know this wouldn’t happen with the Exec 2.x binding. It has been so long since I’ve looked at the 1.x version of the binding that I have no idea if that is how it has always behaved. It is not behaving correctly. The docs for the 1.x version imply that it should only execute the script on a command. But at this point, I doubt this will be fixed in the binding. You will need to adopt Alpoy’s suggestion or move to the 2.x verison of the binding.

On a side note, this Rule has a really strong chance of killing your Rules by using up all the runtime threads. You can only have 5 Rules run at the same time. If I read this correctly, this Rule runs at a minimum every five minutes. Then you sleep for ten seconds and then make a call to a script that can run for up to five minutes. And the Rule can itself change VolvoHeater, VolvoEngine, and VolvoLock causing the Rule to run again. In a worst case scenario you can end up with three or four of your Rules threads tied up for five minutes at a time.

See Why have my Rules stopped running? Why Thread::sleep is a bad idea for a detailed explanation and alternative approaches.

Even with the workaround the command trigger on postUpdate.