Help openhab2, Mqtt, Arduino Uno, relay shield

Hi all, I have openhab2 setup and running from a Pie, I also have my mqtt broker up and running.
I can switch gpio pins using mqtt direct to the arduino but I am lost trying to get openhab to send the mqtt commands.
I hope to pay someone to help me get setup with the basics and I can build on it from there, I can not find any documentation on openhab2, mqtt and arduino UNOs configured as outputs ethernet shield.
Anyone interested in helping me can email or PM me.
As the title states I’m happy to pay anyone that can get me setup.

Setting up OH2<->MQTT is not so complicated.
It is true that good documentation is not so easy to find :slight_smile:

Check out the following for starters:

In principle:
i) Install the MQTT Binding using PaperUI
ii) Configure the /etc/openhab2/services/mqtt.cfg to establish the connection to the broker
iii) Create an item in your /etc/openhab2/items/mqtt.items that is publishing to a topic and is subscribed to another topic
iv) Create a sitemap in your /etc/openhab2/sitemaps/mqtt.sitemap to display your new item

1 Like

Thanks for the helpful reply. I will follow your pointers and see if I can get any further. Do I have to use ESPeasy? I am only using arduinos with ethernet shields so didn’t think ESPeasy would be necessary.

I’m doing something similar (I’m playing with ESP8266 using MQTT to send it commands and get info back from it).

If you’ve got the MQTT broker bit working, and talking to the arduino already, it really is pretty simple to get it hooked into OH.

For my tests I’ve just got a line in my OH sitemap file like:
Group item=Network label=“Infrastructure” icon=“network”

A few lines in my items file like:
Group Network “Intrastructure” (All)
Switch espchk “Check ESP” (Network) { mqtt=">[mosq:Sonoff1in:command:ON:1],>[mosq:Sonoff1in:command:OFF:0]" }
Number espvcc “[%.1f]” (Network) { mqtt="<[mosq:espgetvcc:state:default]" }
Number esprssi “[%.1f]” (Network) { mqtt="<[mosq:espgetrssi:state:default]" }

And a few lines in /etc/openhab2/services/mqtt.cfg like:

And that’s it. The code in my arduino ESP watches for a change on the MQTT channel which triggers stuff (Sonoff1in) and responds with stuff in the other MQTT channels (espgetvcc and espgetrssi), which openhab dutifully displays.


No, it’s not mandatory.
As long as you have your arduinos publishing info to MQTT: you are all set.
Now, you just need to get OH2 to link to the broker and process the info.

I use MQTT and arduinos with ethernet shields all over my house. An example I wrote similar to what you want to do it having a switch item in openhab send a command to MQTT and have the arduino read it and do something. I made a simple command format so when a switch was turned “ON” a message “D1_ON” was written to a MQTT topic “arduino/lightControl/” and the arduino would subscribe to that topic, disassembly the message and turn channel “D1” on. The arduino then posts its status to another topic, “arduino/lightControl/D1” which updates the openhab switch status. I included a link to my github with my arduino code for this. Below is my item definition as well. There are probably better ways to do it but this is the solution I came up with. If you have any question and need any additional help please let my know.


Switch Light_DeskLamp "End-Table Lamp" {mqtt=">[server:arduino/lightControl:command:ON:D1_ON],>[server:arduino/lightControl:command:OFF:D1_OFF],<[server:arduino/lightControl/D1:state:default]", autoupdate="false" }

Thank you guys for such awesome help. really appreciate your time. First time poster in the community, makes me want to learn it all so I can help others. If any of you guys need mains Electrical help let me know as that is my field as an electrician.

1 Like

I’m new to openhab2 and I wonder which mac address, byte server and IP address are the codes referring to.
Does the byte mac address points to the mac address of the RP3 or to arduino ethernet shiled?
How about the byte server and the IP address?
Sorry for asking these questions. Its been 12 days and I still can’t figure out.

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xCB }; // mac add of ??
byte server[] = { 192, 168, 5, 148 }; // IP add of ??
IPAddress ip(192,168,5,134); // IP add of ??

MAC: is the mac address of the Ethernet Shield. If you buy an official Ethernet Shield the MAC is on a sticker on the bottom of the shield.

Server: is the IP address of the MQTT server the the arduino will be connecting too.

ip: is the static IP address of the arduino.

1 Like

I cleaned up the code with this other example I wrote:

Thanks a lot :+1: