I’m new to this smart home thing. So I’m following every tutorial I found but I’m having some problems to make OH2 getting and sending instructions
I have RPi + Raspbian + mosquitto. My goal is to send and receive from/to an arduino to OH2.
Resuming: My mosquitto broker seams to work fine (tested in the rapbian terminal and with a remote pc using mqtt.fx), so the problem must lie somewhere with OH2 config:
1 - I added a file mqtt.cfg to /etc/openhab2/services with the content (saw in a tutorial somewhere):
mqtt:broker.url=tcp://localhost:1883
mqtt:broker.clientId=openhab
mqtt:broker.retain=true
mqtt:broker.async=false
Added 2 items:
Switch ArduinoRelay2 “Nome da tomada 2” {mqtt=">[broker:mikasa/garagem/relay2:command:ON:1],>[broker:mikasa/garagem/relay2:command:OFF:0],<[broker:mikasa/garagem/relay2:state:ON:1],<[broker:mikasa/garagem/relay:state:OFF:0]"}
Number ArduinoThermoresistor “Temperatura [%.1f C]” {mqtt="<[broker:mikasa/garagem/temperatura:state:default]"}
and added those to the sitemap so they can be seen in the OH2 browser
from the raspbian terminal typed:
mosquitto_pub -h localhost -t mikasa/garagem/temperatura -m “22”
My goal is to get and set some relay status and temperature from a thermoresistor.
Can someone spot whats wrong here?
Did you actually install the MQTT Binding? If you had successfully then a default services/mqtt.cfg should >>have been created for you.
I did now… It created a new file called mqtt-eventbus.cfg.
Remove the “mqtt:” part of your configs, that is the old OH 1.x style of configuration back when all the >>configs were in the same file.
I delete the file mqtt.cfg. OH created a new file descrived above.
That file mqtt-eventbus.cfg dont have the same syntax. It also refers to a openhab.cfg file that i cant find.
Have you set up username/password on Mosquitto? If so you need to fill out the mqtt:user and >>mqtt:password fields.
Yes I did.
There should be an mqtt.cfg file too. You don’t want to mess with the mqtt-eventbus.cfg.
There is no longer an openhab.cfg file. That is a 1.x version thing and doesn’t exist for OH 2.x
Not knowing the order you did things I can’t say what happened.But I recommend uninstalling the mqtt binding. Deleting the mqtt*.cfg files. Then reinsall the mqtt binding.
Then fill out the config as documented in the readme, including the username and password.
I did reinstall the mqtt binding. There is now the file mqtt.cfg
I uncommented and chaged changed the lines:
.url=tcp://localhost:1883
.user=myuser
.pwd=mypass
.qos=1
my item is configurated like this
Number ArduinoThermoresistor “Temperatura [%.1f C]” {mqtt="<[broker:mikasa/garagem/temperatura:state:default]"}
In my Windows PC I open mqtt.fx and subscrive the topic "mikasa/#"
then at the RPi terminal typed:
mosquitto_pub -h localhost -t mikasa/garagem/temperatura -m “20”
i’m following the syntax… replaced broker by mosquitto, in mqtt.cfg and in my item same result.
is there a tutorial for OH2 with mqtt? only find for OH1
After some days struggling to get a solution… The thing is… By this date, there is no solution.
The mosquitto version that cames with the raspbian image don’t work with openhab2, and mosquitto can’t be updated for the latest raspbian stretch as shown at https://github.com/eclipse/mosquitto/issues/529
All I can do now is wait for some gentil soul works on a solution
Hello @xSERGIOx,
the mosquitto error is one of the issues why we didn’t yet move the openHABian image to stretch (which we will do very soon). However changes introduced in stretch are pretty much unimportant for openHAB (bluetooth audio improvements might be interesting). Please try again with the latest openHABian image.
Regarding the problems, I believe @rlkoshak has mentioned all that’s needed.
Set up openHAB
Set up an MQTT broker
Check the broker is working, using a desktop client
Install and connect the MQTT binding
Bind a simple item to an MQTT topic, once again check the functionality (desktop client)
Continue
Could you please summarize once again where you are having problems?
Hi
Started again from scratch and followed Rich advise and installed Raspbian Jessie…
I’m stuck at the same point as before…
The mqtt binding is installed, mosquitto is working and openhab don’t get it…
I’m trying to do something simple such as get and set a relay status and get a sensor value such temperature
default.items
Switch ArduinoGarageRelay1 “Grupo Tomadas Parede” {mqtt=">[mosquitto:mikasa/garagem/relay1:command:ON:1],>[mosquitto:mikasa/garagem/relay1:command:OFF:0]"}
Number ArduinoGarageThermoresistor “Temperatura [%.1f C]” {mqtt="<[mosquitto:mikasa/garagem/temperatura:state:default]"}
mqtt.cfg
mosquitto.url=tcp://localhost:1883
mosquitto.user=myuser
mosquitto.pwd=mypass
mosquitto.qos=1
mosquitto.retain=true
mosquitto.async=false
I’m plublishing mqtt messages using the terminal at the RPi and from windows mqtt.fx and each one receibes one another, but openhab dont.
I also notice that Basic UI at the Rpi is not updating values (need to manually refresh), unlike the Paper UI, and at Android (that uses the same Basic UI) does auto refresh… Is this how its supposed to be?
Please use code fences to format your Item and cfg text. It is soo much easier to read when you do:
```
code goes here
```
Are there errors in the log? If you are not publishing something that can be parsed into a Number (e.g. there is white space before or after the digits) OH won’t be able to convert the text into a Number. These will generate error logs.
You should at least see a “Starting MQTT broker connection ‘mosquitto’” in your logs at OH startup if everything is OK. That will narrow the problem down to one of mqtt.cfg or your Items.
Do you have the MQTT Action installed? If so uninstall and reinstall it. This is a known issue and reinstalling the Action fixes it.
I can’t say anything about autorefresh on the Pi, but perhaps the browser on the Pi doens’t support as fast of an autorefresh. All other things being equal, the entries in BasicUI should refresh within a few seconds of the change, usually a lot faster.