Switch Item Status update warnings

I have recently started an openHAB project, I already had MQTT enabled devices installed with custom apps written for control etc but wanted to try openHAB as well.
The problem I have is that several lamps report their status by sending a MQTT message from a common topic with different payloads to indicate the source of the data. When I use this data in openHAB I use several java scripts (one for each lamp) to detect the payloads and return ON or OFF which works OK. So for example lamp1 might send a payload of lamp1=1 for on and lamp1=0 for off, the java script is a simple if (i=“lamp1=0”) return “OFF”; and similarly for the on state. The issue is that because the lamps all publish on the same topic each java script might handle payloads from other lamps, so if lamp2’s payload is processed by lamp1’s java script neither if statement is true so I try to return null (or some other value) to indicate to openHAB that it should ignore this status update. Which sort of works but I get lots of warning messages logged.

So my question is is there a value I can return from the java scripts which will make openHAB silently ignore the status update ?
I have tried several values that I have seen in MAPs like “unknown” “undefined” etc.

Regards
Kevin

Instead of using default, use a REGEX filter. It will only attempt to apply the JS transform when the message matches the REGEX

<[broker:topic:command:JS(js_trans.js):lamp1=(.*)]

I’m not 100% positive of the syntax for the filter. There isn’t an example on the wiki and the description is a little ambiguous. @watou, oh MQTT guru of OH, does the above look right or do I need some quotes?

Thanks Rich, I’ll give that a go in the morning and get back to you.

Do not supply double quotes for the message filter (as in your example @rlkoshak); it’s only documented that way in the wiki. Changing the wiki page to replace " with ``` or add “(without the surrounding double quotes)” to make clear that double quotes aren’t to be given, wouldn’t be a bad idea. :slight_smile:

Small point about lamp1=(.*) – the parentheses aren’t needed since they are intended to “capture” the substring, but this is just a message filter and capturing isn’t used. So the regex lamp1=.* would also successfully match any MQTT message that began with lamp1=.

Thank you both. I implemented the regex matching and now I have a nice quiet log file with no warnings.

I’ve updated the wiki with clarification about not using the surrounding quotes and added an example.

1 Like