Rule not firing with MQTT request

Hi, I’m running Openhab 2.5.0 on RaspberryPi 4b and trying to get a rule to fire when MQTT is received.

I have successfully configured MQTT, a thing (Generic MQTT Thing) and an item (GenericMQTTThing_Sensor) to listen for a data packet from my Sonoff bridge flashed with Tasmota.

In Openhab Control I can see the string label update when a new request from a push button switch is made. It updates the value to the data value received.

"RfReceived":{"Sync":9110,"Low":310,"High":910,"Data":"3EC741","RfKey":"None"}}

I have setup a number item that I would like to use as a counter of how many times the button has been pressed. Name Click_Counter

I also have this rule:

rule "Click Counter"
when 
    Item GenericMQTTThing_Sensor changed
then
    Click_Counter.postUpdate(3) as Number
end

but nothing happens. The item inside my sitemap which is linked to Click_Counter doesn’t get updated. Even when I logEvent(“Rule”,“Clicked”) nothing happens.

Seems like the Item GenericMQTTThing_Sensor changed isn’t correct but I don’t see how it’s wrong. I’ve checked all the spelling but a bit lost as to why this doesn’t work.

Any help appreciated.

The rule does update the counter to “3” all the time, what state do you see?

If the item gets updated to the same value as the existing state (In your case 3) it will not show in the logs
Add a logInfo line in the rule. If it shows up, then you know the rule has triggered.

1 Like

I’ve done this already and nothing gets logged.

logEvent ???

Have you tried logInfo?

I don’t see any state in sitemap but in control UI I can see that the MQTT binding is working correctly because I am able to get the “Data” value and update a generic MQTT item but I need to use the code sent in Data to determine what button/switched was pressed.

Which item?
Can you post you thing and channel config, please?
And your item file

Thanks

As this is about buttons, does this GenericMQTTThing_Sensor get an update to the same value each time you click?
(hint - updates to same value will not trigger rules with changed, by design)

Have you looked in your events.log to see your Item state changes?

I think that’s a terrible name for an Item by the way, you’ll confuse yourself with Items and Things.

I agree about the name but this is only for a maximum of 4 sensors for a work PoC.

2 buttons and 2 PIR’s. I realise there is no change if it’s on the same button click but it will eventually be used with 2 door sensors instead of buttons.

I can see the item state change (when another button is clicked or the PIR’s detect motion) but the rule just doesn’t fire.

Can we see that? The events.log entry?

Can we see the “xxx.rules file load” message from your openhab.log?

that looks like bad syntax to me, but you’ve edited your rule since then. May we see what it looks like now?

Yep. Tried both.

Got it sorted. Needed to have a label in the sitemap with [%s]. Learn something new every day. Thanks everyone for your help.

That wouldn’t stop a rule running, of course.