Rules triggering not working in OH3

Hi everybody,

This is my first post in this community. A few years ago I started with mosquitto/zigbee2MQTT/openHABv2 on a Virtual Machine (CentOS7).
Now I planned to migrate to OH3.
Therefore I prepared a clean install of a new VM (Rocky9.1), borrowed the “Sonoff Zigbee 3.0 USB Dongle Plus” from my OH2 environment, reused the pan_id.

In the new OH3 environment, I created new files, but these are all based on the ones in my OH2 environment.

  • MQTT.things containing two things, a switch and a bulb, (and ofcourse zigbeeMQTT)
  • default.items, containing some details of these things.
  • ohb3_switch.rules
  • switch_action.js (transform)

So, this is a very clean and minimalistic environment.

By means of “mosquitto_pub” I am able to switch on/off the light, so this proves a functioning zigbee network.
By means of the UI of openHAB 3.4.2, I can switch on/off the light, so this proves a connection between openHAB, mqtt and zigbee.

But when I press the physical switch, I can see in the logfile the event: payload ‘{“action”:“left”,…}’,
At this point I would expect the rules file to be triggered. The rules file contains three trigger-conditions: received update left, received command left, changed
but nothing happens.

After updating the rules file, the karaf console shows: updated: UNINITIALIZED, updated: INITIALIZING, updated: IDLE

Ofcourse I read a lot, I searched a lot, but until now I don’t have a clue.
Anyone any idea?

Do you see the event on the Item that triggers the rule in events.log?

No, the only logging for this Item is:
[INFO ] [openhab.event.ItemRemovedEvent ] - Item ‘schakelaar_50action’ has been removed.
during shutdown of openhab

Can you share these, using code fences?

**default.items:**
// Control zigbee2mqtt
Group        gZigbeeMQTT        "Zigbee2mqtt"
String   ZigbeeState                            "Zigbee2mqtt state"                       <switch>              (gZigbeeMQTT)                                   { channel="mqtt:topic:myMQTTBroker:zigbeeMQTT:state"                           }
Switch   ZigbeePermitJoin                       "Permit join new devices"                 <switch>              (gZigbeeMQTT)                                   { channel="mqtt:topic:myMQTTBroker:zigbeeMQTT:permitJoin"                      }
String   ZigbeeLogType                          "Zigbee2mqtt log type"                    <none>                (gZigbeeMQTT)                                   { channel="mqtt:topic:myMQTTBroker:zigbeeMQTT:logType"                         }
String   ZigbeeLogMessage                       "Zigbee2mqtt log message"                 <none>                (gZigbeeMQTT)                                   { channel="mqtt:topic:myMQTTBroker:zigbeeMQTT:logMessage"                      }


// aqara WXKG07LM        schakelaar_double,        OntwikkelSchakelaar
String   schakelaar_50action                    "Action [%s]"                             <wallswitch>          (gZigbeeSwitch)                                 { channel="mqtt:topic:myMQTTBroker:schakelaar_50:action"                       }
Number   schakelaar_50Battery                   "Battery [%d %%]"                         <battery>             (gZigbeeSwitch)                                 { channel="mqtt:topic:myMQTTBroker:schakelaar_50:battery"                      }
Number   schakelaar_50Linkquality               "linkquality [%s]"                        <qualityofservice>    (gZigbeeSwitch)                                 { channel="mqtt:topic:myMQTTBroker:schakelaar_50:linkquality"                  }
Number   schakelaar_50Voltage                   "Voltage [%d mV]"                         <energy>              (gZigbeeSwitch)                                 { channel="mqtt:topic:myMQTTBroker:schakelaar_50:voltage"                      }


// IKEA TRADFRI bulb GU10 WW 400lm
Number   HOB_burolampLinkquality                "Burolamp linkquality [%s]"               <qualityofservice>    (gZigbeeSwitch)                                 { channel="mqtt:topic:myMQTTBroker:HOB_burolamp:linkquality"                   }
Switch   HOB_burolampState                      "Burolamp Status [%s]"                    <Light>               (Hobbykamer, BeganegrondState, HobbykamerState) { channel="mqtt:topic:myMQTTBroker:HOB_burolamp:state"                         }
Dimmer   HOB_burolampBrightness                 "Burolamp Brightness [%d %%]"             <Slider>              (Hobbykamer)                                    { channel="mqtt:topic:myMQTTBroker:HOB_burolamp:brightness"                    }
String   HOB_burolampEffect                     "Burolamp effect [%s]"                    <wind>                (Hal)                                           { channel="mqtt:topic:myMQTTBroker:HOB_burolamp:effect"                        }

MQTT.things:

your code goes hereBridge mqtt:broker:myMQTTBroker                 [ host="localhost", secure=false                                                                                                                                                                         ] 
{

    // zigbee2mqtt Bridge information
  Thing topic zigbeeMQTT "Zigbee2mqtt" @ "tijdelijk_onzichtbaar" {
    Channels:
      Type string : logType                     [ stateTopic="zigbee2mqtt/bridge/log/type"                                                                                                                                                               ]
      Type string : logMessage                  [ stateTopic="zigbee2mqtt/bridge/log/message"                                                                                                                                                            ]
      Type switch : permitJoin                  [ stateTopic="zigbee2mqtt/bridge/config/permit_join"                                                                    , on="true", off="false"                                                         ]
      Type string : state                       [ stateTopic="zigbee2mqtt/bridge/state"                                                                                                                                                                  ]
  }




    // Xiaomi Aqara D1 double key wireless wall switch WXKG07LM
  Thing topic schakelaar_50 "OntwikkelSchakelaar" {
    Channels:
      Type string : action                      [ stateTopic="zigbee2mqtt/schakelaar_50/action"                                                                                                                                                          ]
      Type number : battery                     [ stateTopic="zigbee2mqtt/schakelaar_50/battery"                                                                                                                                                         ]
      Type number : linkquality                 [ stateTopic="zigbee2mqtt/schakelaar_50/linkquality"                                                                                                                                                     ]
      Type number : voltage                     [ stateTopic="zigbee2mqtt/schakelaar_50/voltage"                                                                                                                                                         ]
  }

  //Ikea GU10_Ledlamp LED1837R5 - IKEA TRADFRI bulb GU10 WW 400lm with address ........
  Thing topic HOB_burolamp "burolamp_hobbykamer" {
    Channels:
      Type dimmer : brightness                  [ stateTopic="zigbee2mqtt/HOB_burolamp/brightness"       , commandTopic="zigbee2mqtt/HOB_burolamp/set/brightness"       , on="ON", off="OFF", min=1, max=255, formatBeforePublish="%d" ,  retained=false ]
      Type switch : state                       [ stateTopic="zigbee2mqtt/HOB_burolamp/state"            , commandTopic="zigbee2mqtt/HOB_burolamp/set"                  , on="ON", off="OFF"                                                             ]
      Type number : linkquality                 [ stateTopic="zigbee2mqtt/HOB_burolamp/linkquality"                                                                                                                                                      ]
      Type string : effect                      [ stateTopic="zigbee2mqtt/HOB_burolamp/effect"           , commandTopic="zigbee2mqtt/HOB_burolamp/set/effect"           , blink="Blink", breathe="Breathe"                                               ]
  }
}

Looks OK at first glance. Can you try completely restarting openHAB? Sometimes edits to Things files are not properly picked up.

OH3 runs on a separate virtual machine, that means that I restart openhab and the VM every time that I continue ‘developing’ the migration from OH2 to OH3.

If the Item event isn’t happening the problem lies between the Item and the device. This means one or more of these is going wrong:

  • there is no item channel link or the link is wrong
  • the channel is misconfigured
  • the Broker thing is misconfigured
  • the end device isn’t publishing the message

All I can really suggest is to check each is these in turn and verify each of them, pregnant in reverse order from what I listed above.

In reverse order:

** the end device isn’t publishing the message*
Having two implementations of OpenHAB, the first: my “production”-state OH2 environment, and second: my “development”-state OH3 environment, I move one bulb, one switch and the only one zigbee_usb_dongle from OH2 to OH3 environment and vice versa.
That proves that the end device is publishing messages as it is functioning after it has been placed back in the OH2 environment.

  • the Broker thing is misconfigured
    In my first post I wrote:
    By means of the UI of openHAB 3.4.2, I can switch on/off the light, so this proves a connection between openHAB, mqtt and zigbee.
    I assumed a correct configuration of the Broker thing. Do you agree?

the channel is misconfigured and there is no item channel link or the link is wrong
I think that my previous remark is also valid for these two possibilities?

Besides this, I compared my OH3 and OH2 systems and I noticed that I did not “add-on” the Javascript-Transformation and the JSONPath-Transformation. Even after adding these add-ons nothing changed.

In the file log4j2.xml, I changed “Logger level=INFO” to DEBUG. I could not find relevant information.

Summarized:

  • Clean OS
  • mosquitto
  • zigbee2mqtt
  • unzipped: openhab-3.4.2.zip
  • add-ons: MQTT-binding, zigbee-binding, Javascript-Transformation, JSON-transformation
  • things: See above (file based)
  • items: See above (file based)
var loginfo_rulefile = String::format( "%26s", "ohb3_switch_to_ON.rules" )

rule "switch_to_ON"
when
        Item schakelaar_50action received update left
        or
        Item schakelaar_50action received update single_left
        or
        Item schakelaar_50action received command left
        or
        Item schakelaar_50action changed
then
        var loginfo_rulename = String::format( "%-54s, ", "RULE=switch_to_ON" )
        HOB_burolampState.sendCommand( ON )
        logInfo( loginfo_rulefile, loginfo_rulename + "switched to  ON" )
end

Don’t string items need to have their values in quotation marks?

update "left"

Maybe that’s only required if there are spaces in the value, but I’ve always just done it that way.

It sounds like you’re having trouble getting your physical switch to trigger the rules file in your OH3 environment. You’ve confirmed that your zigbee network and mqtt are working correctly, and you’re able to switch the light on/off via the UI. However, when you press the physical switch, the rules file isn’t triggered even though it contains trigger conditions for the “left” action. Updating the rules file causes it to go through the UNINITIALIZED, INITIALIZING, and IDLE stages in the karaf console, but still no luck. It’s difficult to diagnose the issue without more information, but one possibility could be that the physical switch isn’t properly sending the “left” action to OH3.

@Russ: I tried that but there is no effect.

Yesterday I started from scratch with a new VM, this time not Rocky9 but Rocky8.5 because Rocky9 is not yet supported (GitHub - nodesource/distributions: NodeSource Node.js Binary Distributions).
Murphy was there too: The only test switch in my OH3 environment suffered from an almost empty battery. Battery replaced and two other switches added to OH3, one Ikea, one Xiaomi, just to eliminate issues with a specific switch.

Results so far:
In my new OH3@Rocky8 environment I have exactly the same issue: Rules do not get triggered.
My conclusion to date is: I must have missed an important step…
What could that be???

Installed:

  • Rocky-8.5
  • mosquitto, File /etc/mosquitto/mosquitto.conf: Completely default
  • nodejs: v19.8.1
  • npm: 9.5.1
  • java-11-openjdk
  • setcap ‘cap_net_raw,cap_net_admin=+eip cap_net_bind_service=+ep’ /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-2.el8_7.x86_64/bin/java
  • symbolic link: /usr/lib64/libjli.so → /usr/lib/jvm/java-11-openjdk-11.0.18.0.10-2.el8_7.x86_64/lib/jli/libjli.so

Accounts: openhab, zigbee2mqtt, members of groups tty, dialout

Firewall ports: 8080, 1883
SELinux: permissive

Files: (copied from OH2 environment, but reduced to just a few things)

  • /opt/openhab3/conf/things/MQTT.things
  • /opt/openhab3/conf/items/default.items
  • /opt/openhab3/conf/rules/ohb3_switch_to_OFF.rules
  • /opt/openhab3/conf/rules/ohb3_switch_to_ON.rules
  • /opt/openhab3/conf/transform/schakelaar_action.js

openhab UI:

  • initial account: openhab

Bindings:

  • MQTT Binding
  • openHAB ZigBee Binding

Other Add-ons:

  • Javascript Transformation
  • JSONPath Transformation

Settings:

  • Model : --nothing–
  • Items : Burolamp Status OFF or ON, switching on/off light: works fine
  • Items : Burolamp Brightness: 16, dimmer works fine
  • Items : all other items like Linkquality, Voltage,…: NULL
  • Pages : --untouched–
  • Rules : all rules: green and IDLE
  • Scripts: 0 scripts
  • Schedule: Nothing in the schedule

Commandline:

  • mosquitto_pub -t zigbee2mqtt/bridge/request/health_check -m “” —>>> payload ‘{“data”:{“healthy”:true},“status”:“ok”}’
  • mosquitto_pub -t zigbee2mqtt/HOB_burolamp/set -m ‘{ “state”: “ON” }’ —>>> works fine
  • mosquitto_pub -t zigbee2mqtt/HOB_burolamp/set -m ‘{ “state”: “OFF” }’ —>>> works fine

Two times the same issue. EBCAK??
My conclusion to date is: I must have missed an important step…
What could that be???

It’s been a while since I’ve used DSL, but shouldn’t ON be a string?

HOB_burolampState.sendCommand("ON")

Can you show us the openhab and events logs from around the times that you think the triggering should be occurring?

What’s this used for?

About ON versus “ON”: A quick scan in OH2 rules: I have used both. I remember that in specific cases the quotes are required.

About the logs:
The file events.log shows only events about startting/stopping openhab and events when manipulating light from the UI, like switching on/off and sliding the dimmer.

2023-04-01 12:09:27.189 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampBrightness' changed from 37 to 35
2023-04-01 12:09:27.379 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'HOB_burolampBrightness' received command 34
2023-04-01 12:09:27.382 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampBrightness' predicted to become 34
2023-04-01 12:09:27.383 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampBrightness' changed from 35 to 34
2023-04-01 12:09:27.796 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'HOB_burolampBrightness' received command 31
2023-04-01 12:09:27.798 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampBrightness' predicted to become 31
2023-04-01 12:09:27.800 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampBrightness' changed from 34 to 31
2023-04-01 12:09:27.997 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'HOB_burolampBrightness' received command 29
2023-04-01 12:09:27.998 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampBrightness' predicted to become 29
2023-04-01 12:09:28.002 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampBrightness' changed from 31 to 29
2023-04-01 12:09:38.903 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'HOB_burolampBrightness' received command 4
2023-04-01 12:09:38.905 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampBrightness' predicted to become 4
2023-04-01 12:09:38.906 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampBrightness' changed from 29 to 4
2023-04-01 12:09:56.870 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'HOB_burolampBrightness' received command 3
2023-04-01 12:09:56.872 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampBrightness' predicted to become 3
2023-04-01 12:09:56.873 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampBrightness' changed from 4 to 3
2023-04-01 12:09:57.066 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'HOB_burolampBrightness' received command 2
2023-04-01 12:09:57.067 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampBrightness' predicted to become 2
2023-04-01 12:09:57.069 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampBrightness' changed from 3 to 2
2023-04-01 12:10:01.353 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'HOB_burolampBrightness' received command 1
2023-04-01 12:10:01.354 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampBrightness' predicted to become 1
2023-04-01 12:10:01.357 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampBrightness' changed from 2 to 1
2023-04-01 12:13:13.076 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:topic:myMQTTBroker:schakelaar_50' changed from ONLINE to UNINITIALIZED
2023-04-01 12:13:13.128 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:topic:myMQTTBroker:schakelaar_50' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
2023-04-01 12:13:13.128 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:topic:myMQTTBroker:HOB_burolamp' changed from ONLINE to UNINITIALIZED
2023-04-01 12:13:13.176 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:topic:myMQTTBroker:HOB_burolamp' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)
2023-04-01 12:13:13.177 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:topic:myMQTTBroker:zigbeeMQTT' changed from ONLINE to UNINITIALIZED
2023-04-01 12:13:13.178 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:topic:myMQTTBroker:zigbeeMQTT' changed from UNINITIALIZED to ONLINE
2023-04-01 12:13:13.223 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:topic:myMQTTBroker:zigbeeMQTT' changed from ONLINE to UNINITIALIZED (HANDLER_MISSING_ERROR)
2023-04-01 12:13:13.231 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:broker:myMQTTBroker' changed from ONLINE to UNINITIALIZED
2023-04-01 12:13:13.243 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:broker:myMQTTBroker' changed from UNINITIALIZED to OFFLINE (COMMUNICATION_ERROR): Client sent DISCONNECT
2023-04-01 12:13:13.246 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:broker:myMQTTBroker' changed from OFFLINE (COMMUNICATION_ERROR): Client sent DISCONNECT to OFFLINE
2023-04-01 12:13:13.260 [INFO ] [ab.event.ThingStatusInfoChangedEvent] - Thing 'mqtt:broker:myMQTTBroker' changed from OFFLINE to UNINITIALIZED (HANDLER_MISSING_ERROR)

About openHAB ZigBee Binding:
I think this one shows the state of zigbee. I don’t use it in rules, maybe I dont’t need it all.
I think openhab only communicates with the MQTTBroker, but I am not sure.

Are the last few lines in that log extract when openHAB was shutting down?

Do you have two Mosquitto MQTT brokers in your network?

The last few lines: yes, openhab is shutting down.
Two brokers:
Both VMs have their own MQTT broker, accessed via localhost.
There is only one zigbee dongle, and that one hops from OH2 to OH3 and back.
At any point in time there is only one network active.

Can you, in OH3, create a rule using only the UI to try and perform the same function, and report back?

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: schakelaar_50action
      state: single_left
    type: core.ItemStateUpdateTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      command: ON
      itemName: HOB_burolampState
    type: core.ItemCommandAction

your code goes here==> /opt/openhab3/userdata/logs/events.log <==
2023-04-01 19:53:17.984 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'HOB_burolampState' received command ON
2023-04-01 19:53:17.985 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampState' predicted to become ON
2023-04-01 19:53:17.989 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampState' changed from OFF to ON

Is this what you mean?
When I “Run Now (Ctrl R)” from the UI the light switches on.

And does the trigger work?