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

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

Hello Clint! I have OH loaded but I got pulled into another project. The project is a paid gig so it will be awhile before I get some time to look at OH. I’m sorry for the delay!!

No worries Mark, I feel your pain right now. Work has me bogged down as well :disappointed:

Hope to carve out some time later in the week and maybe over the weekend to try some things. Just trial and error now.

Good luck with the gig!

Please follow the example I gave you earlier.
You don’t need to configure “Device”.

The link from the very first post is dead.

Is there any other place of full tutorial on this topic?

From what I am seeing openHAB is installed and working properly … Looks like the unit your sending MQTT data with isn’t … I fought with my Arduino till I figured it out … You sending bites but not values

Homeautomationforgeeks.com is a good place to start