Openhab2 dont read state from MQTT server :(

  • Platform information:
    • Hardware: Raspberry PI3
    • OS: Openhab2

Hello Wise people! :slight_smile:

Im trying to get the last configured, before implementing a lot of Sonoff devices to my home, and I have finally made it controllable over Wifi from Openhab through MQTT, and it works fine…
But! My initial state isnt working, so if I for instance use a switch, which also have a physical on/off, my interface dont take care (So I can power on a device through IOS homekit, if I then power it off, using the physical switch, it doesnt tell homekit that its off.
I think my problem is just something in the “state” command, but I dont really know why…

-That said: My Rules file is empty, my only plan is to get Openhab to get commands from homekit, and then do the programming in homekit. -I dont know if this is possible, but who shouldnt it? :slight_smile:

A cut from my items file looks like this:

Switch Switch1 “Blæser” (gBlower) [ “Lighting” ] {mqtt=">[broker:sonoffb1/cmnd/power:command:ON:1],>[broker:sonoffb1/cmnd/power:command:OFF:0],<[broker:sonoffb1/stat/POWER:state:ON:1],<[broker:sonoffb1/stat/POWER:state:OFF:0"}

And the MQTT response I get from the sonoff when sending this command is:
and message is: ON

What am I doing wrong, since my “items” just cant tell the state of the unit?

Regards! :slight_smile:


…and surfing the forum, I tried the mapping, but still dont get response on manual switch when my Items file is like this:
Switch Switch1 “Blæser” (gBlower) [ “Lighting” ]

<[broker:sonoffb1/stat/POWER:state:MAP(]", autoupdate=“false”


Your inbound binding are incorrect, they don’t work the same way as the outbound,
You need to map transform the message

In the transform folder create a file call with the following content


Then you item definition

Switch Switch1 “Blæser” (gBlower) [ “Lighting” ] {mqtt=">[broker:sonoffb1/cmnd/power:command:ON:1],>[broker:sonoffb1/cmnd/power:command:OFF:0],<[broker:sonoffb1/stat/POWER:state:map(]", autoupdate="false"}

You can then make another map file call


and your item definition:

Switch Switch1 “Blæser” (gBlower) [ “Lighting” ] {mqtt=">[broker:sonoffb1/cmnd/power:command:*:MAP(], <[broker:sonoffb1/stat/POWER:state:map(]", autoupdate="false"}
1 Like

Wow, fast reply! :slight_smile: Nice!

I dont have time to test right now, but thanks!

-The one thing im wondering, as long the outbound is working now, there is only need for making the transform from, or am I wrong? :blush:

Correct, you don’t need the inbound mapping now.
I made a Typo, the inbound should be working with that:

Switch Switch1 “Blæser” (gBlower) [ “Lighting” ] {mqtt=">[broker:sonoffb1/cmnd/power:command:*:MAP(], <[broker:sonoffb1/stat/POWER:state:MAP(]", autoupdate="false"}

1 Like

Sorry for slow response, had a busy weekend… :slight_smile:
Firstly: Its fun how the Quotation marks you make, dont work on my RPI (need to transform them to " before it goes) :sunny:

-But I still have some issues getting it to read the state…

My MQTT response looks like this:

And I have both 1ON0OFF.MAP and a in /openhab2/transform

And my items file looks like:
Switch Switch1 “Blæser” (gBlower) [ “Lighting” ] {mqtt=">[broker:sonoffb1/cmnd/power:command:*:MAP(], <[broker:sonoffb1/stat/POWER:state:map(]", autoupdate=“false”}

Hope someone can figure out wtf im doing wrong :frowning: :smiley: :smiley:



Your item should work. I can’t see anything wrong with it

1 Like

Hmm, its exactly as you have suggested, and I still dont get the state :slightly_frowning_face:


and Items file as described earlier…

-Just to ensure, I dont need to do anything different about the sitemap file, its only for how its located, and not how it works? :slight_smile:

Does the outbound work?

1 Like

Did you try this?

Switch Switch1 "Blæser" (gBlower) [ "Lighting" ] {mqtt=">[broker:sonoffb1/cmnd/power:command:*:default], <[broker:sonoffb1/stat/POWER:state:default]"}

As you receive ON/OFF you don’t need a transformation.

1 Like

hahaha!! Of course! :slight_smile:

WTF… :):relaxed:

Works like a Charm, thanks both for helping me adress the error, I think I learned something about how to transform a signal to something usefull in Openhab! :slight_smile:


Hi again!

Well, now im into a new problem…
I have bought some other ESP8266 Goodies, and got them working through MQTT…

But! Again: I cant read the state of the item.
The one working looks like this: (The message the ESP send to MQTT)
Topic: Sonoffb1/stat/POWER
and message: ON
My state reading text looks like this:
{mqtt=">[broker:sonoffb1/cmnd/power:command:*:default], <[broker:sonoffb1/stat/POWER:state:default]"}

The new one looks like:
Topic sonoff2/RESULT
and message: {“POWER”:“ON”}

How do I have to change the state, so it knows it only have to look after the things written after "{"POWER: ??

Cheers, and a thanks in advance! :slight_smile:


It uses the JSONPATH transformation
The use in the MQTT binding is documented here:
And the transformation:
Mode info about jsonpath:

1 Like


Thanks a lot for a awsome and fast reply! :smiley:
And sorry im so slow responding :octopus:

Please mark the thread as solved. Thanks