To test triggers within OH3 (without the need for z2m) I created the next rules:
//---------------------------------------------------------------------------------------------------------------------------
rule "HOB_burolampState_changed"
when
Item HOB_burolampState changed
then
var loginfo_rulename = String::format( "%-54s, ", "RULE=HOB_burolampState_changed" )
logInfo( loginfo_rulefile, loginfo_rulename + "switched to xxxx" )
end
//---------------------------------------------------------------------------------------------------------------------------
rule "HOB_burolampState_changed_to_ON"
when
Item HOB_burolampState changed to ON
then
var loginfo_rulename = String::format( "%-54s, ", "RULE=HOB_burolampState_changed_to_ON" )
logInfo( loginfo_rulefile, loginfo_rulename + "switched to ON" )
end
//---------------------------------------------------------------------------------------------------------------------------
rule "HOB_burolampState_changed_to_OFF"
when
Item HOB_burolampState changed to OFF
then
var loginfo_rulename = String::format( "%-54s, ", "RULE=HOB_burolampState_changed_to_OFF" )
logInfo( loginfo_rulefile, loginfo_rulename + "switched to OFF" )
end
//---------------------------------------------------------------------------------------------------------------------------
The openhab.log shows shows that the rules have triggered:
your code goes here==> /opt/openhab3/userdata/logs/events.log <==
2023-04-03 10:23:35.227 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'HOB_burolampState' received command OFF
2023-04-03 10:23:35.228 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampState' predicted to become OFF
2023-04-03 10:23:35.229 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampState' changed from ON to OFF
==> /opt/openhab3/userdata/logs/openhab.log <==
2023-04-03 10:23:35.230 [INFO ] [el.script. report_state.ruleS] - RULE=HOB_burolampState_changed_to_OFF , switched to OFF
2023-04-03 10:23:35.231 [INFO ] [el.script. report_state.ruleS] - RULE=HOB_burolampState_changed , switched to xxxx
==> /opt/openhab3/userdata/logs/events.log <==
2023-04-03 10:23:41.885 [INFO ] [openhab.event.ItemCommandEvent ] - Item 'HOB_burolampState' received command ON
2023-04-03 10:23:41.885 [INFO ] [penhab.event.ItemStatePredictedEvent] - Item 'HOB_burolampState' predicted to become ON
2023-04-03 10:23:41.886 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'HOB_burolampState' changed from OFF to ON
==> /opt/openhab3/userdata/logs/openhab.log <==
2023-04-03 10:23:41.887 [INFO ] [el.script. report_state.ruleS] - RULE=HOB_burolampState_changed , switched to xxxx
2023-04-03 10:23:41.889 [INFO ] [el.script. report_state.ruleS] - RULE=HOB_burolampState_changed_to_ON , switched to ON
But pressing the switch shows in the /var/log/messages file:
Apr 3 10:27:34 ohbserver3 npm[2604]: Zigbee2MQTT:info 2023-04-03 10:27:34: MQTT publish: topic 'zigbee2mqtt/schakelaar_50', payload '{"action":"single_left","battery":100,"device_temperature":29,"linkquality":165,"power_outage_count":164,"voltage":3005}'
Apr 3 10:27:52 ohbserver3 npm[2604]: Zigbee2MQTT:info 2023-04-03 10:27:52: MQTT publish: topic 'zigbee2mqtt/schakelaar_50', payload '{"action":"single_right","battery":100,"device_temperature":29,"linkquality":150,"power_outage_count":164,"voltage":3005}'
But no rules are triggered.