Openhab, MQTT, Mosquitto, ESP8266, Rasperry Pi

Hey !
Im trying to set up a system so i can monitor different sensors like dht22, bmp280, tsl2561, pir. I also want to controll a relay.
I do have all of this stuff working with adafruit io and two “huzzah esp8266”. now i want to use openhab.
on a raspPi 2 i installed mosqitto and openhab.
i also put the mqtt binding in the “addons” folder.
now im trying to figger out how i can connect my working sensor modul and relay modul to mosquitto and openhab.

i think my problem is the software on my two esp.
or the config files of mosquitto and the openhab config file.

some help ? sorry for my bad written english…

Julian,

Mosquitto & openHAB will work well together. I run them both with a few PIRs and a rain water tank level sensor. (I have gone down the path with arduinos & the great mysensors.org stuff)

One of the first things you might want to focus on is getting the MQTT messages into mosquitto and watch a few of them with something like MQTTlens. When you have them successfully showing up in mosquitto then connect them to openhab via the config & items file with something like this,

Number mysDistance "mysDistance" {mqtt="<[mosquitto:mygateway1-out/21/1/1/0/13:state:default]"}
Number WaterLevel "Water Level"

When you have the raw data coming into openHAB you can use rules to do stuff like this,

    rule "Water tank percent"
    	when
    		Item mysDistance received update
    	then
    		val DecimalType distance = mysDistance.state as DecimalType
    		val level = 100.0 - ((distance.intValue / 105.0) * 100)
    		WaterLevel.postUpdate(new DecimalType(level))
    		if ((WaterLevel.state as DecimalType) < 0) {
    		WaterLevel.postUpdate(new PercentType(0))
    		}
    		if ((WaterLevel.state as DecimalType) > 100) {
    		WaterLevel.postUpdate(new PercentType(100))
    		}
    	end

Then of course you can display the information on a sitemap something like this,
Text item=WaterLevel valuecolor=[WaterLevel=="Uninitialized"="lightgray",WaterLevel>75="green",>25="orange",<=25="red"] label="Water Level [%.1f %%]" icon="cistern-50"
(I havn’t successfully got the dynamic icons working yet, if you can see where I am going wrong please point it out)

Regards,
George

thanks for the answer!
tomorrow i will try mqttlens. good idea to go step by step since i dont even know i mosqitto is getting any data.

with your dynamic icon problem… i would look into the demo - sitemap i saw light bulbes change there. on my pi all images are in /opt/openhab/webapps/images
dont know if this will help…

Hi, as you described it here, I´m also using all this stuff, but, im using arduino to control ESP8266 with code from tuanpm ESP8266 Arduino grabs data from sensors and send it via ESP8266 to Mosqitto. On link i have mentioned above are step by step instructions on how to put code into ESP8266 and there are also some simple programs that are working. Also see This Link , maybe you can find something usefull too.

thank you !
i will carefully read those to links.
i really like the second.

im just starting to work with a Pi and openHab. i actually got a Pi to make an openHab project for university…

Hi,
I also just got an esp8266, which I will use as an IR remote for my stereo:) Making scenes called, spotify,radio,chromecast and tv, which then basically switches the hdmi to correct input as well as the stereo. I will let you know how it goes. Write up a guide when i get around to it(It is ski season now so it might take a while…)

Ive done some reading and some people seems to use other broker then Mosquitto, is there any limitations problem in that broker or why should i choose to install a different broker?

Does it not work when you have icon="cistern" in the sitemap, or <cistern> in the items file?

Hey,

I think You should check EasyESP firmware - they made mqtt built in and its working quite nice - they also have probably all probes You need supported in firmware.
I managed to control my switches build on esp within few minutes.

http://www.esp8266.nu/index.php/Main_Page

Regards

watou,

Yes I thought it would be pretty straight forward to get the dynamic icons going (& a neat feature) but it hasnt seemed to work.

It does seem to work when it is set to 0% however when it is a calculated value from the rule, above, it seems to show the uninitialized icon, picture below.

I wonder if it has something to do with the format of the number item generated by the rule.
Do the dynamic icons need a 0 or 1 decimal place value to correctly work?

2016-02-20 10:51:19.132 [INFO ] [runtime.busevents             ] - mysDistance state updated to 107
2016-02-20 10:51:19.132 [INFO ] [runtime.busevents             ] - WaterLevel state updated to 98.980952380952381

Regards,
George

Hi @George_Whitehouse,

what hardware are you using on your esp to measure the water level?
I’m also looking for a solution for my water tank …

Thanks.

sihui,

I am using this one, with a arduino nano and the mysensors sketch.

Cheers,
George

1 Like

Thanks a lot, this waterproof version is exactly what I was looking for!