Integrating nodemcu(esp8266) with openhab via mqtt for relay control

hey guys,
I want to start a home automation project using nodemcu and some relays, raspberry pi as openhab server. I’ve tried numerous tutorials but no success up till now.

I found out that I’ve to use MQTT to communicate with the nodemcu(esp8266) which in turn will be connected to the relays.

till now i’ve installed openhab, mqtt on pi and it’s working properly .
still not getting the arduino code right for the nodemcu.

please help ! i’m new to all this.
how do i integrate openhab with esp8266 using mqtt. a simple code would be extremely helpful
thanks.

i’ve tried examples such as these but they don’t work as they are for different boards
http://makezine.com/projects/building-a-home-automation-system-with-openhab-to-control-leds-wirelessly/

Do you allready bought the hardware? Try this module from sonoff. https://www.itead.cc/sonoff-wifi-wireless-switch.html cheap and ready to use.
There is one custom firmware to work only with MQTT. https://github.com/arendst/Sonoff-MQTT-OTA

Regards,

thanks jmv for the speedy reply, but unfortunately i’ve already bought the hardware.

and i’ve also got the setup working through terminal window like this https://www.youtube.com/watch?v=PgsH43Tpqjc&t=613s

now i’ve to find a way to integrate it with openhab any suggestions?

hi @abhi
you can use ESPEasy, it is a firmware that works with all ESP8266 modules including NodeMCU and it has got an onborad http server for management and fully integrated with MQTT which of course you can control from OpenHAB
http://www.letscontrolit.com/wiki/index.php/Main_Page
it is pretty easy to setup and configure, i have a bunch of these nodes around the house for multiple functions

I would second ESPEasy. I use it for relays, buttons/switches, etc.

If I need something more complex, I use the Homie framework. It takes care of handling the MQTT connection so you can just worry about the logic of your code.

thanks guys for the help… i finally figured it out.
this video - https://www.youtube.com/watch?v=PgsH43Tpqjc&t=613s
was extremely helpful for understanding the mqtt concept.
from the video i understood that the ESP’s have subscribed to a particular topic and that i just have to publish a message through openhab on the same topic.