EasyESP and MQTT

Happy Friday Folks,

I need a little help in receiving MQTT from a simple implementation of an esp8266. I am able to communicate with the esp-01 and can control an LED using the following item:

Switch MQTTLED (test) {mqtt=“>[mymosquitto:/ESP01/gpio/2:command:ON:1],>[mymosquitto:/ESP01/gpio/2:command:OFF:0]”}

My problem is that I cannot receive the status of a button. Here are the two Contact items that I’ve tried.

Contact MQTBTN (test) {mqtt=“>[mymosquitto:/esp01/switch/button:state:MAP(switch.map)]”}
Contact MQTBTN1 (test) {mqtt=“>[mymosquitto:/esp01/switch/button:state:default)]”}

For support information, here’s the log from the esp-01

SW : State 0
HTTP : Delay 1000 ms
MQTT : Topic /esp01/switch/button
SW : State 1
HTTP : Delay 1000 ms
MQTT : Topic /esp01/switch/button

The Switch .ino file is attached as well. _P001_Switch.pdf (62.0 KB)

You’ve not supplied your switch.map so I can’t see how you’re handling the mapping. You’ve also not said what errors if any you receive so at the moment I can only say the following:

Contact items only allow states OPEN and CLOSED, not 0 or 1, so there may lie your problem. Maybe your item should be defined as a Switch, or maybe you need to map 1 and 0 to OPEN and CLOSED.

Each item generates the following error.

2015-12-10 21:22:38.542 [ERROR] [i.internal.GenericItemProvider] - Binding configuration of type ‘mqtt’ of item ?MQTBTN1? could not be parsed correctly.
org.openhab.model.item.binding.BindingConfigParseException: Configuration ‘mymosquitto:/esp01/switch/button:state:default)’ is not a valid outbound configuration: Configuration requires 5 parameters separated by ‘:’

2015-12-10 21:22:38.520 [ERROR] [i.internal.GenericItemProvider] - Binding configuration of type ‘mqtt’ of item ?MQTBTN? could not be parsed correctly.
org.openhab.model.item.binding.BindingConfigParseException: Configuration ‘mymosquitto:/esp01/switch/button:state:MAP(switch.map)’ is not a valid outbound configuration: Configuration requires 5 parameters separated by ‘:’

Here is the switch.map which works for my zwave contacts.

0=OPEN
1=CLOSED

Thanks for you help.

If these are messages from your ESP to openHAB then it’s an inbound message, which means your arrow needs to be “<” and not “>”.

Apart from that the rest looks good so if that doesn’t work I’m kind of out of ideas!

1 Like

That put me in the right direction. I’m getting the message to the server. However, I cannot get Openhab to recognize the conact via the GUI

Here’s the events.log

2015-12-11 21:33:23 - MQTBTN state updated to 1.00
2015-12-11 21:33:26 - MQTBTN state updated to 0.00

Any ideas?

seems that you have to put

0.00=OPEN
1.00=CLOSED

in your mapping-File

My setup:
EasyESP firmware on nodemcu.
Openhab2
Raspberry pi running openhab2 with mosquito mqtt broker.
In openhab2, i have install mqtt binding and MAP transformation.

home.items file for one of the switch.

Switch F2_Bedroom_Power “Power Outlet” (F2_Bedroom, gPower) {mqtt=">[broker:/nodemcu01/sw1/swcmd/cmd:command:ON:gpio,16,1], >[broker:/nodemcu01/sw1/swcmd/cmd:command:OFF:gpio,16,0], <[broker:/nodemcu01/sw1/swstat:state:MAP(binary.map)]"}

binary.map file content.

root@openHABianPi:/etc/openhab2/items# cat …/transform/binary.map
1=ON
0=OFF

Using above i can able to command my switch ( on/off ) also,it updates the state of the switch if its turned ON/OFF externally.