poki123
(poki123)
April 1, 2018, 3:57pm
1
Hello, I tried several times to use regex filter for incomming mqtt messages, but without any success.
Please, could you help me? Im interesting only for the messages “Connection Lost”, everything else I want to ignore.
Switch Heating_switch “Infra panel” [ “Switchable” ]
{ mqtt="<[broker:/sonoff_1/status/LWT:state:MAP(switch_status.map):REGEX(.Lost. )]" }
Thank you,
Juraj
poki123
(poki123)
April 2, 2018, 6:21am
3
Hi, thank you, but this is not working.
vzorglub
(Vincent Regaud)
April 2, 2018, 7:49am
4
Do you get any error messages in your log?
poki123
(poki123)
April 2, 2018, 8:18am
5
No, there is nothing in the log.
After using REGEX filter, the input string (Connected / Connection Lost) is fully ignored and no transform was made.
vzorglub
(Vincent Regaud)
April 2, 2018, 8:43am
6
I am at work now.
There are some regex validators online.
rlkoshak
(Rich Koshak)
April 2, 2018, 3:18pm
7
REGEX(.*Connection Lost.*)
The REGEX must match the full message. .* matches 0 or more of any characters.
Just using . matches 0 or 1 character. In particular, the message may have two characters at the end if it uses Windows style new lines.
poki123
(poki123)
April 2, 2018, 5:24pm
8
Hello Rich, thank you for the answer, but this is not working too.
This is my items file (without regex filter everything is working, but I have warning messages in log file for Connected event, which i want to filter:
Switch Heating_switch “Infra panel” [ “Switchable” ]
{ mqtt=">[broker:/sonoff_1/gpio/12:command:ON:1],
>[broker:/sonoff_1/gpio/12:command:OFF:0],
<[broker:/sonoff_1/status:state:MAP(switch_status.map)],
<[broker:/sonoff_1/Relay/Switch:state:MAP(switch_status.map)],
<[broker:/sonoff_1/status/LWT:state:MAP(switch_status.map):REGEX(.*Connection Lost.*)]" }
and switch_status.map :
Connection\ Lost=OFF
0=OFF
1=ON
Switch:\ ON=ON
Switch:\ OFF=OFF
There is no error in the log file.
OS Openhabian
Openhab version 2.3.0~20180331153334-1
binding-mqtt1 - 1.12.0.SNAPSHOT
rlkoshak
(Rich Koshak)
April 2, 2018, 6:41pm
9
If there is any whitespace before or after “Connection Lost” then your switch_status.map will not be able to map it to OFF.
But why not just tell it to go to OFF without the map?
<[broker:/sonoff_1/status/LWT:state:OFF:REGEX(.*Connection Lost.*)]
“Connection Lost” always means OFF so there is no need to map.
1 Like
poki123
(poki123)
April 2, 2018, 7:28pm
10
I tried this, but still without success :-(.
The map is working correctly, until I use the regex_filter.
I also tried to use only “Lost” string (in case of white space) and manually publish LWT message Lost via MQTT.fx, but this is not working too.
rlkoshak
(Rich Koshak)
April 2, 2018, 9:22pm
11
Doh! You don’t use “REGEX( )” for the message matching. You can only use regular expressions so the REGEX is redundant.
This example from the docs :
Number humidity "humidity [%.1f%%]" {mqtt="<[broker:weatherstation/readings:state:JS(convertPercent.js):humidity=.*]"}
will match all messages that start with “humidity=”.
So you need:
<[broker:/sonoff_1/status/LWT:state:OFF:Connection Lost]
If there is a chance of there being leading or trailing whitespace use
<[broker:/sonoff_1/status/LWT:state:OFF:.*Connection Lost.*]
poki123
(poki123)
April 3, 2018, 4:22am
12
Thank you Rich, this one is working great :-ň
<[broker:/sonoff_1/status/LWT:state:OFF:Connection Lost]
vzorglub
(Vincent Regaud)
April 3, 2018, 2:49pm
13
Doh! indeed…
That proves it again
Read the docs, again and again and again…
Thanks
1 Like