Regex Mosquitto

146 views
Skip to first unread message

Mark Thompson

unread,
Sep 11, 2015, 4:27:25 PM9/11/15
to openhab
Hi All, 

This might be a very newbie question but I'm struggling with the REGEX on Mosquitto Bindings. 

Example:

Number temp1 "Wired Temperature 3 [%.1f C]" <temperature> (MainSpace) {mqtt="<[mymosquitto:temp:state:REGEX(TA)]" }
Number temp2 "Wired Temperature 3 [%.1f C]" <temperature> (MainSpace) {mqtt="<[mymosquitto:temp:state:REGEX(TB)]" }

I'm sending a command similar to this aTBTMPA22.00 and aTATMPA21.00 There TB or TA is the address of the sensor and 22.00 or 21.00 is temp. 

Whatever I do, temp1 takes on both TA both TB and the same for temp2. 

Also another question. How would I extract only the temp part once I've got it once reacting to the correct message....

This is driving me mad! :)

T

watou

unread,
Sep 11, 2015, 5:30:20 PM9/11/15
to openhab
Are you using a single MQTT topic to hold values for two different sensors, so one sensor publishes to the "temp" topic and then another sensor later publishes to the same "temp" topic?  That's pretty hard to work with.  Ideally, each sensor would just publish a basic value (like "22.00") to a distinct MQTT topic, so subscribers could just pick them up without having to do REGEX or other fancy parsing on them.

Could you instead publish what you want in the temp1 item to the MQTT topic "temp/A" and publish what you want in the temp2 item to MQTT topic "temp/B"?

If you need to have all the other characters preceding the value you want, you would have REGEX(aTBTMPA(.*)) to just capture the number.  But it would be best to just publish the temperature to a distinct topic and be done with it using default instead of REGEX(...).

Mark Thompson

unread,
Sep 11, 2015, 5:48:44 PM9/11/15
to openhab
Thanks for your input!

Yes the simplest way is to use a unique topic for each sensor but I'm experimenting with combining items onto one topic. 

What I'm getting now when using 

{mqtt="<[mymosquitto:temp:state:REGEX(^aTATMPA(.+)$)]" }

is that it extracts the temp value from aTATMPA21.00 so 21.00 but on the aTBTMPA22.00 it just goes straight through. So it's working in part but doesn't work when a message comes in that doesn't meet the filter. It should block it!

Thanks for your help so far. 

T

On Friday, 11 September 2015 21:27:25 UTC+1, Mark Thompson wrote:

watou

unread,
Sep 11, 2015, 6:16:16 PM9/11/15
to openhab
I think the experiment of using one topic will continue to frustrate, because if the regex doesn't match because the value was intended for the other item, it will still set the wrong item.  Is there some other justification in using one topic for two purposes?

Also, if you joined https://community.openhab.org and continued there, you could probably get more eyes on your subject, as the openHAB Google Group is really supposed to be phased out and only here for historical reasons.

Mark Thompson

unread,
Sep 11, 2015, 6:23:51 PM9/11/15
to openhab
Thanks. I'll post there. 

The main reason is that we are using a two way communicating to a python script running on the same machine. That collects from and writes to exterior hardware. We are using this communication system across the system and we'd like to have a little Regex transform to read it at both the OpenHab end and the python end as opposed to using millions of different mosquitto topics. However this might not be the right way to do it as you say. Open to suggestions. 

Thanks for your help. 


On Friday, 11 September 2015 21:27:25 UTC+1, Mark Thompson wrote:
Reply all
Reply to author
Forward
0 new messages