I have already added the spaces to my rules in anticipation of 2.3 - but I’m waiting for the release, it’ll probably take a few days to sort OH out after the update.
Regarding Thread::sleep, everyone seems to think this is a terrible thing - does it sleep all threads? or just the rule that’s running? How would I replace it? (I know some people say “use timers” but how?)
Here is an example rule where I use it:
rule "Skype State Machine"
when
Item TV_Skype_State changed
then
/* States for State machine
0 - idle
1 - just switch to Anynet
2 - incoming Skype call, switch to Anynet and set up for receive
3 - switch back to HDMI 1 (end of Skype Call?)
*/
logInfo("Skype", "Skype state changed to: " + TV_Skype_State.state)
// 0 is idle state - do nothing
if(TV_Skype_State.state == 0) return;
if(TVON.state != ON && TV_Power.state != ON) {
logInfo("Skype", "But Samsung TV is OFF, so ignore")
postUpdate(TV_Skype_State, "0")
return;
}
if (TV_Skype_State.state == 1 || TV_Skype_State.state == 2) {
logDebug("Skype", "Answering Skype Call")
if (TV_Status.state != "ONLINE") {
sendCommand(TVTools, "KEY_TOOLS")
Thread::sleep(250)
sendCommand(TVKey_Enter, "KEY_ENTER")
Thread::sleep(250) //might need this, might not...
sendCommand(TVKey_DOWN, "KEY_DOWN")
Thread::sleep(250)
sendCommand(TVKey_Enter, "KEY_ENTER")
Thread::sleep(250)
sendCommand(TVKey_Enter, "KEY_ENTER")
}
else
sendCommand(TVSource_Name, "HDMI-CEC")
if(TV_Skype_State.state == 2) {
//wait for source to switch to HDMI-CEC
// use google home mini 1 to announe incoming call
say("Incoming Skype Call, Incoming Skype Call")
var int count = 0
if (TV_Status.state != "ONLINE") count = 31
while(TVSource_Name.state != "HDMI-CEC" && count <= 30) {
Thread::sleep(100) //100 ms delay
count = count + 1
}
logDebug("Skype", "Answer Exit Loop: TV Source is: " + TVSource_Name.state)
Thread::sleep(2000)
//select video answer button on Skype screen
sendCommand(TVKey_DOWN, "KEY_DOWN")
Thread::sleep(250)
sendCommand(TVKey_DOWN, "KEY_DOWN")
Thread::sleep(250)
sendCommand(TVKey_DOWN, "KEY_DOWN")
Thread::sleep(250)
sendCommand(TVKey_LEFT, "KEY_LEFT")
}
}
else if (TV_Skype_State.state == 3){
logDebug("Skype", "Hangup Skype Call")
var int count2 = 0
if (TV_Status.state != "ONLINE") {
sendCommand(TVInput_HDMI, "KEY_HDMI")
count2 = 31
}
sendCommand(TVSource_Name, "HDMI1/DVI")
var prev_source = TVSource_Name.state
//sendCommand(TVInput_HDMI, "KEY_HDMI")
while(TVSource_Name.state != "HDMI1/DVI" && count2 <= 30) {
Thread::sleep(100) //100 ms delay
if (TVSource_Name.state != prev_source && TVSource_Name.state != "HDMI1/DVI") {
prev_source = TVSource_Name.state
logDebug("Skype", "Hangup: Sending HDMI command")
sendCommand(TVInput_HDMI, "KEY_HDMI")
}
count2 = count2 + 1
}
//Thread::sleep(2750)
//sendCommand(TVInput_HDMI, "KEY_HDMI")
logDebug("Skype", "Hangup Exit Loop: TV Source is: " + TVSource_Name.state)
}
else postUpdate(TV_Skype_State, "0")
logInfo("Skype", "Skype Rule Ended")
end
This rule reacts to an update from an android box, that there is an incoming Skype call, the rule then sends the remote control commands to put the TV on the correct input. The delays are due to the hardware response timing.
How would you do this without Thread::sleep?
Thanks,