"Could not invoke method" error in if/then statement when sending command to Ecobee HVAC mode item

In yet another Ecobee/auto rule, I am trying to implement my own auto function because our master bedroom Ecobee also controls the nursery temperature and we keep the AC/Heat setpoints too close to use the built-in auto functionality. So my thought was to switch to heat if, in cool mode, the temperature drops more than 2 degrees below the heat setpoint. Likewise, the rule will switch to cool mode if, in heat mode, the temperature rises more than 2 degrees above the A/C set point.

Unfortunately, I’m getting the following error in my if/then statement:

2016-04-21 07:10:17.802 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Upstairs HVAC Auto Controller’: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null

Here are the items:

Number tNurseryTemperature “Temperature: [%.1f °F]” (g2FTemp) { ecobee="<[XXX

String tMBRhvacMode “[%s]” { ecobee="=[XXX#settings.hvacMode]" }
Number tMBRCoolPoint “Cool Setpoint: [%.1f]” { ecobee="<[XXX#runtime.desiredCool]" }
Number tMBRHeatPoint “Heat Setpoint: [%.1f]” { ecobee="<[XXX#runtime.desiredHeat]" }

Here’s the rule:

rule "Upstairs HVAC Auto Controller"
when
Item tNurseryTemperature changed or
Item tMBRCoolPoint changed or
Item tMBRHeatPoint changed or
Item tMBRhvacMode changed
then
if (tNurseryTemperature.state >= (tMBRCoolPoint.state + 2.0f) && tMBRhvacMode == “heat”) {
sendCommand(tMBRhvacMode, “cool”)
pushover(“Bedroom/Nursery HVAC has transitioned from heating mode to cooling.”)
}
else if (tNurseryTemperature.state <= (tMBRHeatPoint -2.0f) && tMBRhvacMode = “cool”) {
sendCommand(tMBRhvacMode, “heat”)
pushover(“Bedroom/Nursery HVAC has transitioned from cooling mode to heating.”)
}
end

You need to cast the number states to a DecimalType. You also need to compare the state of tMBRhvacMode, not the Item.

if((tNurseryTemperature.state as DecimalType) >= ((tMBRCoolPoint.state as DecimalType) +2.0f) && tMBRhvacMode.state == "heat") {

Thank you, that is working well, but now I’m seeing another error. It looks like the logic is working fine, but I’m seeing an error trying to change the HVAC mode:

2016-04-21 13:24:20.063 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Upstairs HVAC Auto Controller’: Could not invoke method: org.openhab.core.items.GenericItem.setState(org.openhab.core.types.State) on instance: tMBRhvacMode (Type=StringItem, State=cool)

It’s strange because I use the same setup on a different HVAC mode Item (i.e., sendCommand) in another rule in the same rule file and it does not give me an error.

I almost always recommend using the method on the Item rather than the sendCommand actions.

tMBRhvacMode.sendCommand("cool")

It has always been less reliable to use the sendCommand (and postUpdate) actions and the errors have become exacerbated when 1.8.2 was released.

I’m still getting the same error with this command:

tMBRhvacMode.sendCommand(“heat”)

2016-04-21 16:10:15.389 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Upstairs HVAC Auto Controller’: Could not invoke method: org.openhab.core.items.GenericItem.setState(org.openhab.core.types.State) on instance: tMBRhvacMode (Type=StringItem, State=cool)

This may be a silly question, but is it worth rebooting before I do more troubleshooting?

It is never a bad idea.

I’ve no idea what could be causing this. I wonder if it is being generated by the Ecobee binding.

Rebooting fixed the issue! I’ve been doing a lot of work on my rules, so maybe it put that item in a funky state.

On a related question, is it worth going through my current rules to change from using the sendCommand action to using the method on the Item?

I wouldn’t. But if you encounter problems keep it in mind as something to try.

Unfortunately, the same error is back:

2016-04-25 06:38:43.410 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule ‘Upstairs HVAC Auto Controller’: Could not invoke method: org.openhab.core.items.GenericItem.setState(org.openhab.core.types.State) on instance: tMBRhvacMode (Type=StringItem, State=cool)

I’m going to change the title to make it clear that this relates to an Ecobee item in an attempt to help resolve it. Would running at the debug level help?

It looks like you are assigning “cool” to the item variable. You instead need == and not = to do the comparison. One “trick” is to put the constant on the left of the == to help safeguard the common error of using a single =, like:

"cool" == tMBRhvacMode

Thank you!

For some reason, I was having an issue previously with sending the command to change the HVAC state when transitioning to “cool” (the comparison was configured correctly for that if/then statement), so I figured it was the same issue.