[Solved] Rule stops working after some time with error "Could not invoke method (...) on instance: null

Hello Community,

I have some problems with my rules (or maybe some other part of the system). I have some rules which fire when a Z-Wave PIR is activated and switch on certrain lights. The rules themselves are working, but after the system is up for some time, they cause an error in openhab.log. Sometimes they work a few days, sometimes only some hours. Here is one example:

rule "Bewegungsmelder Keller Flur PIR1 an"
when
  Item PIR_Sensor_1 changed from OFF to ON then
 
  KG_Flur_Licht_Timer.sendCommand(ON)
  sendTelegram("bot1", "Flur Licht Keller Timer aktiv (PIR1)!")
  
end


rule "Keller Licht Automatik"
when
  Item KG_Flur_Licht_Timer changed
then
  KG_Flur_Licht.sendCommand(KG_Flur_Licht_Timer.state)
  sendTelegram("bot1", "Flur Licht Keller aktiv!")
end

The rule usually works fine, but after some time, this error appears when it fires:

events.log:

2020-05-23 19:54:36.227 [vent.ItemStateChangedEvent] - PIR_Sensor_1 changed from OFF to ON
2020-05-23 19:54:36.239 [ome.event.ItemCommandEvent] - Item 'KG_Flur_Licht_Timer' received command ON
2020-05-23 19:54:36.246 [vent.ItemStateChangedEvent] - KG_Flur_Licht_Timer changed from OFF to ON

openhab.log

2020-05-23 19:54:36.250 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Keller Licht Automatik': 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

I first thought it’s an issue with the MQTT broker (since KG_Flur_Licht is a Tasmota), but the Tasmota responds to commands when switched with Sitemap for example, as you can see from events.log it works fine when switched "manually:

2020-05-23 20:17:22.646 [ome.event.ItemCommandEvent] - Item 'KG_Flur_Licht' received command ON
2020-05-23 20:17:22.650 [nt.ItemStatePredictedEvent] - KG_Flur_Licht predicted to become ON
2020-05-23 20:17:22.705 [vent.ItemStateChangedEvent] - KG_Flur_Licht changed from OFF to ON

The error also occurs with other rules which control Z-Wave devices.

BTW, the problem occured in various versions of OH2 since 2.2 I think and it feels it gets worse with every release, at the moment I am on 2.5.5.

Any hints what can be the problem?

Remove the .state. You can’t send a command to a state, only the item.
Should be like this:

KG_Flur_Licht.sendCommand(KG_Flur_Licht_Timer)

@lfs_alp5

I changed the rule like you suggested:

rule "Keller Licht Automatik"
when
  Item KG_Flur_Licht_Timer changed
then
  KG_Flur_Licht.sendCommand(KG_Flur_Licht_Timer)
  sendTelegram("bot1", "Flur Licht Keller aktiv!")
end

But the error still is thrown when it fires:

2020-05-23 21:06:05.430 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Keller Licht Automatik': 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

As for me, I think it’s not a problem with the rule syntax itself, as the rule works for a while (e.g. after reboot), and then stops after system is up for a while.

It is about the state, but perhaps not what you expect.
https://community.openhab.org/t/plclogo-solution-logo-output-switching/64264/8

I’m sorry, completely misread it…trying to get 2 kids to sleep while reading the forums on my phone…chaos :see_no_evil: disregard what i said

Puh, found a solution while looking around in other threads, this way it works:

rule "Keller Licht Automatik"
when
  Item KG_Flur_Licht_Timer changed
then
  KG_Flur_Licht.sendCommand(KG_Flur_Licht_Timer.state.toString)
  sendTelegram("bot1", "Flur Licht Keller aktiv!")
end

Now I am curious if it still runs tomorrow :wink:

@rossko57: Thanks, your post pointed me to the right direction, so I marked it as solution.