Away mode (rule) not firing harmonyStartActivity correctly

So I’ve been using OpenHAB for some time now, and finally got around to learning about rules and scripts. I’ve successfully implemented quite a few rules for various items in my home, and so far so good, until now. I’ve finally wrote a rule to turn off items when I leave the house, or when I come back home, and most of my rule works like a charm, except when it comes to firing harmonyStartActivity. Here’s the relevant details: OpenHAB 1.8.3

Items:

String Harmony_Activity         "Activity [%s]" (Living_Room_TV)        { harmonyhub="*[LR:currentActivity]" }
String HarmonyHubOff            "Power OFf"     (Living_Room_TV)        { harmonyhub=">[start:PowerOFF]" }

Sitemap: The sitemap is using a selection with mappings, and it works flawlessly.

Selection item=Harmony_Activity label="Activity" icon="television" mappings=[PowerOff=Off, "Watch TV"="Watch TV", "Watch Apple TV"="Watch Apple TV", "Play PS4"="Play PS4", "Play Retro"="Play Retro", "Listen to Music"="Listen to Music"]

Rule:

rule "Mode Away"
when
         Item Occupied changed to OFF
then
         if (Daytime.state != ON) {              //its night//
         logInfo("Mode", "Night away mode initiated")
                 if (Harmony_Activity != "Off") {        //Check living room tv//
                 logInfo("Mode", "Away: Turning off tv")
                 harmonyStartActivity(LR,"PowerOff")
                 }
                 if (Away_Mode != ON) {          //Check for away mode//
                 logInfo("Mode", "Away: mode activated")
                 sendCommand(Away_Mode, ON)
                 }
         }
         else if (Daytime.state == ON) {         //its daytime//
         logInfo("Mode", "Day away mode initiated")
         }
 // more if statements //
end

Everything before and after the harmonyStartActivity line fire like a champ. But every time I see “Away: Turning off tv” in the logs, it errors out and doesn’t turn off the tv.

What I’ve tried:
harmonyStartActivity(LR,“PowerOff”)
harmonyStartActivity(“LR”,“PowerOff”)
harmonyStartActivity(“LR,PowerOff”)
harmonyStartActivity(LR,PowerOff)
harmonyStartActivity(“PowerOff”) //pulled from wiki//
harmonyStartActivity(PowerOff)
harmonyStartActivity(“Power Off”)
harmonyStartActivity(“Off”)
harmonyStartActivity(Off)
harmonyStartActivity(start,“PowerOff”)

Log: With all of the above I get various error messages, I can supply them if need be.
but the log for harmonyStartActivity(PowerOff), from the wiki looks like this (and doesn’t turn off the tv):

2016-06-18 09:52:36.548 [INFO ] [org.openhab.model.script.Mode ] - Away: Turning off tv
2016-06-18 09:52:36.768 [WARN ] [c.a.internal.AutoUpdateBinding] - InstantiationException on

What am I missing here? I’ve been pulling out what hair I have left trying to figure this out…
Any help is greatly appreciated! I’ve spent hours trying to get this rule just right, and it’s so close!

//edit: I’ve updated the above to include the missing }'s & updated formatting

Your rule has 5 opening curly brackets but only 3 closing curly brackets.

Thanks @Udo_Hartmann my actual rule has all the }'s after each if, it seems that the forum editor ate them. Any suggestions on the proper formatting of the harmonyStartActivity command?

Sorry, I don’t own a harmony…

To avoid changes in code, please don’t use quotation but three backticks ` ahead and behind the code, so formatting will be like

rule "Mode Away"
when
    Item Occupied changed to OFF
then
    if (Daytime.state != ON) {              //its night//
        logInfo("Mode", "Night away mode initiated")
        if (Harmony_Activity != "Off") {        //Check living room tv//
            logInfo("Mode", "Away: Turning off tv")
            harmonyStartActivity(LR,"PowerOff")
        }
        if (Away_Mode != ON) {          //Check for away mode//
            logInfo("Mode", "Away: mode activated")
            sendCommand(Away_Mode, ON)
        }
    }
    else if (Daytime.state == ON) {         //its daytime//
        logInfo("Mode", "Day away mode initiated")
    }
// more if statements //
end

:slight_smile:

So what’s the log for harmonyStartActivity("PowerOff") ?

Ah. And did you use a qualifier in openhab.cfg?

Nice, thanks I’ll update the above post.

The relevant log for the command harmonyStartActivity(“PowerOff”) is:

2016-06-18 16:53:19.831 [INFO ] [org.openhab.model.script.Mode ] - Away: Turning off tv
2016-06-18 16:53:19.895 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Mode Away': No client '' defined

My relevant sections out of openhab.cfg are (where X’s replace personal information):

harmonyhub:LR.host=192.168.X.X
harmonyhub:LR.username=XXXX@XXXXX
harmonyhub:LR.password=XXXXXXXXXX

So I guess my qualifier would be: LR
Is ‘qualifier’ the same as ‘client’, if so, what’s the format for this?

Thanks!

As you did setup a qualifier, it has to be used in the action definitions, too.

Did you setup an item

String LivingRoomTVOff            "Power OFF"     (Living_Room_TV)        { harmonyhub=">[LR:start:PowerOff]" }

? you could try to use this item instead:

LivingRoomTVOff.sendCommand("PowerOff")

Of course, even if this works, it would be a workaround. Maybe other user with a working harmony binding can help…