Install and setup OpenHAB 2.0 with Mosquitto and ESPEasy+HC-SR04

I figure it out how it does work in Openhab2, the current stable release.

I created manually an mqtt.cfg file
I updated the addons.cfg and added mqtt to the binding part.

It’s my guess that selecting mqtt on openhab2 on a raspberry pi only installs the needed mqtt binaries yet no configuration files. (and thus also does not allow to update the mqtt binding setting in paperUI

Great! That makes sense…glad you got it worked out.

1 Like

Hi all, hate to post this here but am struggling at finding this on the web, believe it or not. I have even posted to other forums and no luck.

I am not a gpio guru but have worked with oh for awhile and love it. I have a wemos D1 R2 that is connected to my wifi just fine. I am running the espeasy and working nicely. I have mqtt setup in oh and will connect it all as i go along here. So to my question, i have four relays that i need to connect to the wemos. i can find the schematic but its really greek to me. i just need to know what pins to connect and where to connect the relays. i find tons of youtube videos but they dont show the connection details, just how the code works etc. i guess thats just the simple part that everyone should know but this is my first foray into the electronic side.

Can someone point me in the right direction or just help with some simple dummy information like, dude, just connect pin x to one relay, pin y to another and your good to go.

thanks!

and by the way, this thread is great!

Hello Clint! I can try to help. It’s been awhile so I may struggle a bit. Can you share a pics of your setup to get started?

Sure thing Mark! thanks!

so one pic shows just the wemos and the initial ssr. That ssr will then connect to another ssr then out to pumps. I have spent hours reading and that seemed to be the recommended setup but than again, maybe i dont need the ssr in the middle. in any case, i still dont know how best to connect the wemos to the relays. i have a 5v power supply that will connect to the wemos.

wemos with first ssr

wemos with second set of ssr’s

My working example is here.

SSR is wired to D4, VCC and GND. Note: my SSR is a “Low Level Trigger”.

@boilermanc I would suggest to eliminate intermediate SSRs and use a cheap buffering module like this.

Thanks andrew, this is the small ssr module that i am using.

sainsmart relay

specs are in there. if i am understanding it correctly, it should trigger anywhere from 2.5 - 20v. and then have enough output to trigger the next level ssr. at least that was the thought. the stepper that you sent, is that up or down? can’t really tell by the link.

The spec for the larger ssr would be:

Specification of the SSR
Input: 3V-32V DC
Control: 24V~380V AC
Current: 25A

So on the SSR board IN1, IN2, IN3, IN4 each need to be wired to a GPIO on the Wemos. GND from the Wemos needs to go to GND on the ssr board

How many volts and how much current will the second set of SSR carry?

I am not sure what you power source is for the wemos and ssr board so I want to make sure I understand

It seems I have exactly the same SSR on my module.
There is a schematics on the product page you published - your module seems to be “high level trigger”, so to activate the relay you will need to bring the corresponding NodeMCU output pin high. As a result you should be able to see the LED on the SSR board. Please test up to this step.
From the second picture you posted I’ve got a feeling that your wiring for power SSRs is incorrect. Please check with the manufacturer’s datasheet.
The module I mentioned is actually not a stepper, but “The ULN2003A is an array of seven NPN Darlington transistors capable of 500 mA, 50 V output” (wikipedia). It’s purpose is to protect and offload the NodeMCU outputs and provide enough current [from external source!] to the big SSR for example.

Some research on the control current:
The big SSR you have - Fotek SSR-10DA - has Trigger Current of 7.5ma per datasheet.
For ESP8266 I/O Imax is 12ma per datasheet.
So it looks like you can connect your big relays to your Wemos board directly without using the Sainsmart board. But to be on the safe side I would use something like ULN2003A as mentioned earlier.

Thanks to both for your insight. I will see if i can grab one of the steppers. First step might be to just get the first ssr to fire and that way i can test my code and connections. then worry about the next step of what is the line or not. so given that, which of the gpio’s should i use on the wemos to connect to that relay?

thanks!

It does not matter which GPIO as long as it digital. Is there a schematic for the wemos? I am not familiar with wemos so I need some help from you

hey mark, here is a link to one of the retailers. it has the pin information…

wemos d1 r2

GPIO4,5,14,12 should work fine. For future reference keep in mind that the
GPIOs are dual function. If you needed on/off functionality AND i2C the
esp8266 may not fit your needs. Also the A0 is for (INPUT) reading analog
signals like temp sensor…it cant do I/O

Make sure you init the GPIOs to the state that you need for your SSR on
startup

Hey Mark, made some excellent progress today between work and the games starting up!

In any case, i have my esp and openhab talking! that was pretty euphoric.

I setup the wemos on pin 14 = D5. I have the 5v wire from the wemos connect to vcc on the relay and the ground to the ground.

in my mqtt setup i have mymosquitto as my broker name

in my esp setup i have

Device: switch input
Name: HTPump1
0 delay
i put in a idx value but dont think it matters for now
pin 14
pull up not selected
inversed not selected
switch type: switch
normal switch
and then i put in Switch for the value name 1

under hardware i just kept the pins at “default”

i then put this line into the items:

Switch HTPump1 {mqtt=">[mymosquitto:hottub/gpio/14:command:ON:0],>[mymosquitto:hottub/gpio/14:command:OFF:1]"}

so close but no cigar… i get nothing when i hit my switch in the sitemap.

starting up OH i get this in the log:

2017-03-17 17:07:11.803 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2017-03-17 17:07:11.806 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mymosquitto'
2017-03-17 17:07:12.270 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mosquitto'```

i have checked my mqtt.cfg and i do not a see a broker named mosquitto. i have mymosquitto but not just mosquitto.


then this follows:


MqttException (0) - java.net.NoRouteToHostException: No route to host (Host unreachable)
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:34)[283:org.openhab.io.transport.mqtt:1.9.0]
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:553)[283:org.openhab.io.transport.mqtt:1.9.0]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_121]
Caused by: java.net.NoRouteToHostException: No route to host (Host unreachable)
at java.net.PlainSocketImpl.socketConnect(Native Method)[:1.8.0_121]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)[:1.8.0_121]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)[:1.8.0_121]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)[:1.8.0_121]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)[:1.8.0_121]
at java.net.Socket.connect(Socket.java:589)[:1.8.0_121]
at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:66)[283:org.openhab.io.transport.mqtt:1.9.0]
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:538)[283:org.openhab.io.transport.mqtt:1.9.0]
… 1 more
2017-03-17 17:07:15.431 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection ‘’


not sure what that means. i also dont understand the <broker>. i have updated the cfg file with mymosquitto as mentioned above.

the esp is connecting out of all of this... but nothing is triggered on the from the sitemap. in fact, i do not get an entry in the log when i trigger the switch from the sitemap.


```php
Frame label="Hottub Pump 1 {widget:switch,icon:water-pump}" {
			Switch item=HTPump1 label="Hottub Pump 1"

thanks!

Have you confirmed that you can send/receive with mqtt commands on a command line? I don’t think that’s your problem but it might be. I need to review the ESP app and oh again in order to help. It’s been over a year since I had it running at home. I’ll do that tomorrow and get back to you

Hey Mark, yes, it worked on the command line and with the mqttfx tool. Thanks for helping with this. i am out of town this week so will not be able to work on it.

Excellent tutorial for newbie like me. After following your tutorial, started to receive topics and able to subscriber all the topics in openhab2 on pi but unfortunately its not displaying distence value in UI kindly help me where I went wrong
Following is all topics in pi

1490883513: mosquitto version 1.4.11 (build date Mon, 20 Feb 2017 22:47:27 +0000) starting
1490883513: Using default config.
1490883513: Opening ipv4 listen socket on port 1883.
1490883513: Opening ipv6 listen socket on port 1883.
1490883514: New connection from 192.168.1.3 on port 1883.
1490883514: New client connected from 192.168.1.3 as mqtt_414b658f.e382cc (c1, k60, u’openhabian’).
1490883514: Sending CONNACK to mqtt_414b658f.e382cc (0, 0)
1490883514: Received SUBSCRIBE from mqtt_414b658f.e382cc
1490883514: /LightSensor/ZDHT/Temperature (QoS 0)
1490883514: mqtt_414b658f.e382cc 0 /LightSensor/ZDHT/Temperature
1490883514: Sending SUBACK to mqtt_414b658f.e382cc
1490883514: Received SUBSCRIBE from mqtt_414b658f.e382cc
1490883514: /LightSensor/ZDHT/Humidity (QoS 0)
1490883514: mqtt_414b658f.e382cc 0 /LightSensor/ZDHT/Humidity
1490883514: Sending SUBACK to mqtt_414b658f.e382cc
1490883514: Received SUBSCRIBE from mqtt_414b658f.e382cc
1490883514: /LightSensor/System time/up (QoS 0)
1490883514: mqtt_414b658f.e382cc 0 /LightSensor/System time/up
1490883514: Sending SUBACK to mqtt_414b658f.e382cc
1490883514: Received SUBSCRIBE from mqtt_414b658f.e382cc
1490883514: /LightSensor/Singnal/ (QoS 0)
1490883514: mqtt_414b658f.e382cc 0 /LightSensor/Singnal/
1490883514: Sending SUBACK to mqtt_414b658f.e382cc
1490883514: Received PUBLISH from mqtt_414b658f.e382cc (d0, q0, r0, m0, ‘LightSensor’, … (5 bytes))
1490883539: New connection from 192.168.1.147 on port 1883.
1490883539: New client connected from 192.168.1.147 as ESPClient3 (c1, k15, u’mqtt’).
1490883539: Sending CONNACK to ESPClient3 (0, 0)
1490883539: Received SUBSCRIBE from ESPClient3
1490883539: /MarksESP8266/# (QoS 0)
1490883539: ESPClient3 0 /MarksESP8266/#
1490883539: Sending SUBACK to ESPClient3
1490883543: Received PUBLISH from ESPClient3 (d0, q0, r0, m0, ‘/MarksESP8266/MarksHCSR/Distance’, … (2 bytes))
1490883543: Sending PUBLISH to ESPClient3 (d0, q0, r0, m0, ‘/MarksESP8266/MarksHCSR/Distance’, … (2 bytes))
1490883544: Received PUBLISH from ESPClient3 (d0, q0, r0, m0, ‘/MarksESP8266/System time/up’, … (6 bytes))
1490883544: Sending PUBLISH to ESPClient3 (d0, q0, r0, m0, ‘/MarksESP8266/System time/up’, … (6 bytes))
1490883548: Received PUBLISH from ESPClient3 (d0, q0, r0, m0, ‘/MarksESP8266/MarksHCSR/Distance’, … (3 bytes))
1490883548: Sending PUBLISH to ESPClient3 (d0, q0, r0, m0, ‘/MarksESP8266/MarksHCSR/Distance’, … (3 bytes))
1490883553: Received PUBLISH from ESPClient3 (d0, q0, r0, m0, ‘/MarksESP8266/MarksHCSR/Distance’, … (3 bytes))
1490883553: Sending PUBLISH to ESPClient3 (d0, q0, r0, m0, ‘/MarksESP8266/MarksHCSR/Distance’, … (3 bytes))

[16:20:50] openhabian@openHABianPi:~$ sudo mosquitto_sub -t /MarksESP8266/MarksHCSR/Distance
[sudo] password for openhabian:
216
215
218

Kindly help any one

Thanks

Make sure you have the variable defined properly in OH2. I forget the syntax for formatting but I know it’s very specific. Let me know if you need some help and I will pull my project code

Hey Mark, back again. did you get a chance to look through your configuration? think i am close but not quite there.

First of all thank your very very much for your prompt reply. as I told you I am newbie in this so kindly also let me know were (I mean which file) I have to define correct variable sorry to give you headache thanks