My Harmony Binding is working fine, but I’m trying to capture the current state of the Master Bedroom TV and then perform some actions based on that result. I have the code below in my home.rules file:
rule "TV Testing"
when
Time cron "0 55 13 ? * *"
then
logInfo("Current Master Harmony_Activity", Master_Harmony_Activity.state.toString)
If(Master_Harmony_Activity.state.toString == "PowerOff") sendCommand(Desk, HSBType::GREEN)
end
I checked the log and have the entries below:
2016-10-25 13:38:01.143 [INFO ] [urrent Master Harmony_Activity] - PowerOff
2016-10-25 13:38:04.067 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule Sunset TV
java.lang.RuntimeException: The name 'If(<XBinaryOperationImplCustom>)' cannot be resolved to an item or type.
The log correctly captures that the current state of the TV is “PowerOff”, but the “if” command doesn’t execute and throws the error.
No, I changed the name of the rule because I didn’t want anyone to think I was trying to tie it to Sunset yet. It will “eventually” be included with the rest of my sunset activities, but I simplified the rule name for the post.
Have you tried some very simple code inside the if statement yet? I also think you can remove the toString in the if maybe?
I’m just giving ideas to try…
Yes, I picked the desk item because if I take out the IF statement, the desk will turn on at the chron time.
I also have other IF statements that work find using the Harmony, so I think the issue is in the compare of the Harmony state.
Sample of working IF statement on the Harmony:
rule "Pause Master Harmony"
when
Item Nightstand received update
then
var hsbValue = Nightstand.state as HSBType
if (hsbValue.getBrightness() > 0) HarmonyMasterPause.sendCommand("Pause")
else HarmonyMasterPlay.sendCommand("Play")
end
Removing toString from the end of Master_Harmony_Activity.state.toString
assigning (temporarily) the state to a new variable and testing the new variable? (just to test)?
you could log the String variable as well just to make sure you’re getting it correctly.
Just trying to share steps I’d try - not saying I know the answer here…
Removing the toString - Yes, I got the same results.
Adding loginfo without toString - gives me an error that there are incompatible types
Assigning a temp variable - Yes, I got the same results I’m getting with the code below.
rule "TV Testing"
when
Time cron "0 11 8 ? * *"
then
logInfo("Current Harmony_Activity", Master_Harmony_Activity.state.toString)
If(Master_Harmony_Activity.state == "PowerOff") sendCommand(Desk, HSBType::GREEN)
end
Log file:
2016-10-26 08:10:26.251 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'home.rules'
2016-10-26 08:11:01.128 [INFO ] [o.m.s.Current Harmony_Activity] - PowerOff
2016-10-26 08:11:03.373 [ERROR] [.o.m.r.i.engine.ExecuteRuleJob] - Error during the execution of rule TV Testing
java.lang.RuntimeException: The name 'If(<XBinaryOperationImplCustom>)' cannot be resolved to an item or type.
Glad I could help - sorry it took me a couple of iterations to figure it out.
I did most of my item/rule configuration in the beginning using a linux text editor (no syntax highlighting or “smarts”). I’ve recently installed SmartHome Designer (I think the recommended version is still 0.7.0) and I really like it.
Since my OH installation is on linux, I shared my configuration folder (in my case /etc/openhab2) and mapped it to my local windows machine. Then I installed Eclipse SmartHome Designer (0.7.0) and pointed it to my mapped configuration folder. When you open the .items, .sitemap or .rules files in the Designer, it provides error feedback which can save HOURS of head scratching.
Once you’re there, make sure you download the appropriate 0.7.0 release version for your system (see screenshot). There’s no installation, you just unzip and run SmartHome-Designer.exe (on WIndows) but there are prerequisites but I think as long as you have a recent version of Java you’re good to go.