[SOLVED] Rule not triggering when update comes from JSONPATH

So I have this rule:

rule "Portão exterior a abrir/fechar com comando"

when
   Item Sensor_Portao_Exterior received update
then
   switch Sensor_Portao_Exterior.state {
      case "OFF": {
         sendBroadcastNotification("Portão exterior aberto.")
      }

      case "ON": {
         sendBroadcastNotification("Portão exterior fechado.")
      }
   }
end

And it’s not working when the update comes directly from JSONPATH, it only works when I change the item directly.

Already tried with received command “OFF” and with changed, without the switch cases as well and it did not worked.

Already tried to logInfo and it seems that the rule is simply not triggered at all when the item changes due to JSONPATH.

Again, if I change the item directly in Paper UI or in APP, it works flawlessly.

So nothing logged in openhab.log but in my events.log it properly receives the changes from JSONPATH:

2020-11-24 11:31:10.108 [vent.ItemStateChangedEvent] - Sensor_Portao_Exterior changed from ON to OFF
2020-11-24 11:31:14.272 [vent.ItemStateChangedEvent] - Sensor_Portao_Exterior changed from OFF to ON

So… yeah, I’m stuck!

I’m not often using switch/case expressions so I modified this a bit.

Please test the following one, this should wok.

rule "Portão exterior a abrir/fechar com comando"

when
   Item Sensor_Portao_Exterior changed from ON to OFF or
   Item Sensor_Portao_Exterior changed from OFF to ON
then
	if(Sensor_Portao_Exterior.state == OFF){
		sendBroadcastNotification("Portão exterior aberto.")
	}
	if(Sensor_Portao_Exterior.state == ON){
		sendBroadcastNotification("Portão exterior fechado.")
	}   
end
1 Like

There we go, we have the solution! :smiley:

Thanks a lot. :slight_smile:

The problem is that you have a State here, but strings in your case statements. Either change this to a string…

switch Sensor_Portao_Exterior.state.toString {

… or remove the quotes around ON and OFF.

1 Like