MQTT-Binding

How can I extract the Value out of the following MQTT state:

“true02021-08-03T08:29:15.3646081Z02021-08-03T08:29:15.3646081Z0”

I only need the Value “true”. Can i do this with XPath expression?
What I have to insert?

What else can the value be? Looks like a job for REGEX, “get string until first numeric character”.


The state look like this (see picture).
I need the value in “/Value/Value/Boolean/”
The value can be true or false.

Oh, that’s rather different. You could still REGEX as you know the values, but the “proper” way would be XPATH, yes.

Ok, but how that this work?

I found this on OpenHAB Help:

I tried the following:
“XPath:/Value/Boolean/text()”
“XPath:/Value/Value/Boolean/text()”
“XPath:/DataValue/Value/Value/Boolean/text()”

But nothing worked.
Have you idea?

XPATH is an installable add-on, so first make sure that you’ve installed it.

I suppose you could look at the docs, instead of guessing

The namespace is important here.

Example

Note that once you’ve created your channel with some guessed transformation, the binding doesn’t always recognize if you edit it later. Once you have your best guess in place, if it doesn’t seem to work, then restart the MQTT package to make sure it uses your latest edit.

1 Like

Now it works!
The problem was actually the namespace.
I had to insert the transformation like this:

"/[name()=‘html’]/[name()=‘head’]/[name()=‘title’]/text()"
XPath:/
[name()=‘DataValue’]/[name()=‘Value’]/[name()=‘Value’]/*[name()=‘Boolean’]/text()

Thank you very much for your help!

1 Like

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.