Hey guys. I have a rule to basically make two tplink switches a three way switch. I have a rule to make the two mirror each other’s state. The rule has worked for several months. I had one little hiccup where the rule stopped working randomly, but a restart of the DiskStation that i have OH2 installed on seemed to get it working again. Here is the rule.
rule "CPkitchen1"
when
Item CP_Kitchen_Lights changed
then
val LightsState = CP_Kitchen_Lights.state
CP_Kitchen_Slave.sendCommand(LightsState)
end
rule "CPkitchen2"
when
Item CP_Kitchen_Slave changed
then
val SlaveState = CP_Kitchen_Slave.state
CP_Kitchen_Lights.sendCommand(SlaveState)
end
A few more months pass and the rule stops working again, and this time a restart was not helpful. I take a look at the log files and I noticed this error. Obviously it has something to do with the “sendCommand” part of the rule but I don’t know enough to figure out the details. Any help would be greatly appreciated!
2018-10-25 11:10:28.887 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'CPkitchen2': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.Number) on instance: null
From the most recent startup in the event.log file
2018-10-25 10:56:58.977 [hingStatusInfoChangedEvent] - 'tplinksmarthome:hs200:5a5dac5b' changed from UNKNOWN to ONLINE
2018-10-25 10:56:59.113 [vent.ItemStateChangedEvent] - CP_Kitchen_Lights changed from NULL to OFF
and
2018-10-25 10:56:58.947 [hingStatusInfoChangedEvent] - 'tplinksmarthome:hs200:D47A1E' changed from UNKNOWN to ONLINE
2018-10-25 10:56:59.046 [vent.ItemStateChangedEvent] - CP_Kitchen_Slave changed from NULL to OFF
Makes sense that you can’t send a NULL. What other logging can I add?
If there’s a glitch in communications to the TPlink box - router reboot, WiFi interference? - the binding will most likely set state to UNDEF or maybe NULL for the duration.
That’s a “normal event” really, and your rule won’t deal with it nicely.
rule "CPkitchen1"
when
Item CP_Kitchen_Lights changed to ON or
Item CP_Kitchen_Lights changed to OFF
then
val LightsState = CP_Kitchen_Lights.state
CP_Kitchen_Slave.sendCommand(LightsState)
end
rule "CPkitchen2"
when
Item CP_Kitchen_Slave changed to ON or
Item CP_Kitchen_Slave changed to OFF
then
val SlaveState = CP_Kitchen_Slave.state
CP_Kitchen_Lights.sendCommand(SlaveState)
end
10:58:08.177 [INFO ] [del.core.internal.ModelRepositoryImpl] - Loading model 'CP_Lights.rules'
10:58:12.448 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'CP_Kitchen_Lights' received command ON
10:58:12.461 [INFO ] [smarthome.event.ItemStateChangedEvent] - CP_Kitchen_Lights changed from OFF to ON
10:58:12.535 [INFO ] [pse.smarthome.model.script.SlaveState] - The Master state is ON
10:58:12.546 [INFO ] [pse.smarthome.model.script.SlaveState] - The Slave state is OFF
10:58:12.558 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'CPkitchen1': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.Number) on instance: null
10:58:16.458 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'CP_Kitchen_Slave' received command ON
10:58:16.464 [INFO ] [pse.smarthome.model.script.SlaveState] - The Master state is ON
10:58:16.466 [INFO ] [smarthome.event.ItemStateChangedEvent] - CP_Kitchen_Slave changed from OFF to ON
10:58:16.472 [INFO ] [pse.smarthome.model.script.SlaveState] - The Slave state is ON
10:58:16.480 [ERROR] [untime.internal.engine.RuleEngineImpl] - Rule 'CPkitchen2': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.Number) on instance: null
@rossko57 i guess that could be the case, as this is multiple buildings all in a PtMP setup. However everything has a solid connection. no packet loss between my laptop (currently in the same building as the server) and the devices (different building).
And as stated above, the states are defined, not NULL or UNDEF
rule "CPkitchen2"
when
Item CP_Kitchen_Slave changed to ON or
Item CP_Kitchen_Slave changed to OFF
then
val SlaveState = CP_Kitchen_Slave.state
CP_Kitchen_Lights.sendCommand(SlaveState)
end
When you save the state of the light in a val SlaveState you are storing a state object.
It can be any generic state object because we didn’t specify the type. Therefore the sendCommand method is struggling to convert the val into a meaningful command for the item.
So if we add the .toString it will pull out the value of the state to a String (In this case “ON” or" OFF") and that can be used as a command.
I assumed, and am probably wrong, that SlaveState would have been either a State or Command type Object which sendCommand should have been able to handle. But I bet you are absolutely right, it’s an Object and sendCommand can’t handle that.
makes good sense! Thank you both for all your help!!! hopefully this will be the end of my problems with this particular rule. now on tho the next one!