Basically:
I want to start my projector with my switch. It should send for ON: \rpow=on#\r and for OFF: \rpow=off#\r)
I also want to query the projector how many hours its been on and what the power status is (on or off).
So sending a command \r*ltim=?#\r asks the projector and it responds back.
Group gViewsonic_1_PX747 "gViewsonic_1_PX747" (gCinema) ["Projector"]
Switch Viewsonic_1_PX747_Switch "Projector Power Switch" (gViewsonic_1_PX747) ["Switch"] { channel="serial:serialDevice:sensors:relay:power" }
String Viewsonic_1_PX747_LampStatus "Projector Lamp status" (gViewsonic_1_PX747) { channel="serial:serialDevice:sensors:relay:lampstatus" }
Switch Viewsonic_1_PX747_Lamp "Projector Lamp Status Switch" (gViewsonic_1_PX747) ["Switch"]
String Viewsonic_1_PX747_PowerStatus "Projector Power status" (gViewsonic_1_PX747) { channel="serial:serialDevice:sensors:relay:powerstatus" }
Switch Viewsonic_1_PX747_Power "Projector power Status Switch" (gViewsonic_1_PX747) ["Switch"]
The serial .thing:
Bridge serial:serialBridge:sensors [serialPort="/dev/ttyUSB1", baudRate=9600] {
Thing serialDevice relay [patternMatch =".*"]
{
Channels:
Type switch : power [onValue ="\r*pow=on#\r", offValue ="\r*pow=off#\r"]
Type string : lampstatus [stateTransformation ="REGEX:.*?LTIM=(.*?)#"]
Type string : powerstatus [stateTransformation ="REGEX:.*?POW=(.*?)#"]
}
}
And a rule that send the commands I wanted. I know there is a difference in itemname.sendCommand(“string”) and sendCommand(itemname, “string”).
But only the latter worked…
Also made the rule to fire every night at oclock: 23.59.59 so that lamphours are logged in databases so I can graph usage.
rule:
rule "Projector power Status"
when
Item Viewsonic_1_PX747_Power received command
then
sendCommand(Viewsonic_1_PX747_PowerStatus, "\r*pow=?#\r")
Viewsonic_1_PX747_Power.postUpdate(OFF)
end
rule "Projector Lamp Status"
when
Time cron "0,59 0,59 0,23 ? * * *" or
Item Viewsonic_1_PX747_Lamp received command ON
then
sendCommand(Viewsonic_1_PX747_LampStatus, "\r*ltim=?#\r")
Viewsonic_1_PX747_Lamp.postUpdate(OFF)
end
This only took me around 8 hours today to figure out…