Error with String Item in Rules when string is Empty

I’m having trouble with rules when using a String item type when the value has been set to “” and I attempt to access it in a rule.

Here’s the portion of the rule that’s relevant:

logInfo(commandName, "Before");

if(thermostatHvacMode.state.format("%s") == "cool"
   && thermostatEquipmentStatus.state.format("%s") != ""){

      logInfo(commandName, "here");

I’ve tried the above using state.toString() and just state in place of state.format("%s") and all had the same result. If thermostatEquipmentStatus is “”, I get the following log messages:

2018-06-14 08:53:46.249 [INFO ] [del.script.ClimateControl-FamilyRoom] - Before
2018-06-14 08:53:46.249 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Climate Control Family Room': An error occurred during the script execution: index=1, size=1

However, if thermoststatEquipmentStatus is set to “fan” then there isn’t an error.

2018-06-14 08:55:57.373 [INFO ] [del.script.ClimateControl-FamilyRoom] - Before
2018-06-14 08:55:57.373 [INFO ] [del.script.ClimateControl-FamilyRoom] - here

For testing, I’m setting that value using this rule and modifying the dimmer that triggers it to set the string value. It’s set from a binding IRL.

rule "Temp equipment status"
when Item testDimmer changed
logInfo("temp", "clearing equipment status");
  • Platform information:
    • Hardware: 64 Bit Intel Core 2 Duo
    • OS: Fedora 25
    • openHAB version: openHAB 2.2.0 Release Build on Docker

I searched the forum and found a couple other places where this error message occurred. They seemed to be misuses of logInfo() by not passing at least 2 arguments. That’s not the case here. It seems to be related to the string item being empty. Not sure why… Anybody know what causes this?

Maybe test the string with

 && !thermostatEquipmentStatus.state.tostring().isEmpty() 

Good idea. Unfortunately the log looks exactly the same when I tried it…

Also, I wondered if it was something the binding behind thermostatEquipmentStatus was doing where it didn’t like me manually changing those values. Changing all instances of thermostatEquipmentStatus with tempthermostatEquipmentStatus in the rule file and creating the item

String tempthermostatEquipmentStatus "Temp Status"

Did not change the error. It still happens the same way.

I dont understand what you are saying.

How schould this look like?

thermostatEquipmentStatus is an item that is tied to a binding (ecobee). Since I am calling a postUpdate in a rule (“Temp equipment status”) posted in the first post, I wondered if the binding was having trouble with that and that was the cause of the error.

Before my 2nd post above, I tried two things:

  1. Use !thermostatEquipmentStatus.state.tostring().isEmpty() like you suggested. This gave the same error.
  2. Replace all uses of thermostatEquipmentStatus with newly defined vertual String Item tempthermostatEquipmentStatus. I did this to avoid the possibility of the binding having a problem with how I set the value. Still the same error.

Does that make sense?

Please post the full rule. Maybe try to delete all other rules in the same file.

I couldn’t post the full rule because there was too much in it, but I tried doing a simple rule containing just the if in question.

rule "Climate Control Family Room"
  Item testSwitch changed
  var commandName = "ClimateControl-FamilyRoom"; 

    logInfo(commandName, "Before");
    // If thermostat is in cooling mode and either the AC or the fan is on
    if(thermostatHvacMode.state.format("%s") == "cool"
    && thermostatEquipmentStatus.state.toString() != ""
      logInfo(commandName, "here");
      logInfo(commandName, "Other");

When I did this, I didn’t get the error. I don’t understand how the original rule could work in some situations and not others with the exact same code, but it looks like I may just have to rebuild the original rule from scratch and test after adding each bit of code.

That’s good enough for me.

Thanks for the help.

You don’t need the semicolon.

have a look in the language used for rules called Xtend