Harmony Binding - Item State

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"
	Time cron "0 55 13 ? * *"
	logInfo("Current Master Harmony_Activity", Master_Harmony_Activity.state.toString)
	If(Master_Harmony_Activity.state.toString == "PowerOff") sendCommand(Desk, HSBType::GREEN)

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.

Thanks for any assistance!

Your log refers to an error in the rule “Sunset TV” yet your post shows “TV Testing”. Was that a mistake?

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…

Can you also post your “Desk” item definition?

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"
	Item Nightstand received update
	var hsbValue = Nightstand.state as HSBType

	if (hsbValue.getBrightness() > 0) HarmonyMasterPause.sendCommand("Pause")
	else HarmonyMasterPlay.sendCommand("Play")

Have you tried:

  • 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…

I appreciate the assistance!

  • 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"
	Time cron "0 11 8 ? * *"
	logInfo("Current Harmony_Activity", Master_Harmony_Activity.state.toString)
	If(Master_Harmony_Activity.state == "PowerOff") sendCommand(Desk, HSBType::GREEN)

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.

Might sound silly - but your “if” is lower case in your other example but has a capital “I” in your harmony example.

I just tested using OpenHAB Designer and If is not recognized but “if” is… I think you’ve got a silly little typo.

1 Like

OMG, you’re correct! THANK YOU!! I had no idea.

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.

You can find the designer [on github]

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.

1 Like