Page 1 of 1

Espeasy and openhab - NEED HELP, PLEASE

Posted: 06 May 2019, 21:16
by mihai.icey.ro
Hello,

I set up the ESP with the openhab to control a switch. I don't know why it doesn't work.

home.sitemap

Code: Select all

Frame label="MQTT Test"{
 Switch item=LampaBanc label="LED" icon="light"
}
home.items

Code: Select all

Switch LampaBanc {mqtt=">[localbroker:/LampaBanc/gpio/5:1.00],>[localbroker:/LampaBanc/gpio/5:command:OFF:0.00]"}
}
mqtt.cfg

Code: Select all

mqtt:localbroker.url=tcp://192.168.1.7:1883
Any help? Thanks

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 06 May 2019, 23:05
by ThomasB
Not enough information to provide a thorough answer. Issues like yours should include screen shots of the Main, Controller, and Device pages.

But for a start, I suggest changing the home.items to this format:

Code: Select all

Switch LampaBanc {mqtt=">[localbroker:/LampaBanc/gpio/5:command:ON:1],>[localbroker:/LampaBanc/gpio/5:command:OFF:0]"}
Your mqtt.cfg does not look correct. If the MQTT broker is on the same IP as your OpenHAB (installed on same machine), then this is the typical syntax:

Code: Select all

localbroker.url=tcp://localhost:1883
Also, there are two different MQTT bindings available to OpenHab. Your syntax and files are for the old legacy MQTT Binding (1.x) version. I use the old 1.x binding, so if you are running the new 2.x version then I won't be able to help (and you should ignore all my suggestions above).

And if you haven't tested the MQTT broker then I suggest you use a tool and confirm it is working. For example, Chrome MQTTLens addon.

- Thomas

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 07 May 2019, 07:34
by mihai.icey.ro
Thank you for the help. Here are the screenshots from the mqtt. MQTT Broker, you mean the hosting server? If yes, it's on the same machine. I can't see in the MQTT Binding the version 1.x just the new one.. :(


Image
Image
Image
Image
Image

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 07 May 2019, 09:21
by s0170071
Have you enabled the legacy add-on option in the Configuration > System > Add-on Management?
If I remember it correctly, it doesn't hurt to use the IP address of the broker instead of "localbroker".

You probably already use it, but there are numerous tools for spying on mqtt messages, so please make sure you already see the message on your broker. Otherwise debugging this will drive you insane.

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 07 May 2019, 20:34
by mrwee
Which openhab version are you on?

Also note, that it's against best practice to have a leading '/' in the subscribe/publish settings. It still works, if configured correctly it's just best to avoid

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 07 May 2019, 21:23
by mrwee
Just took a look at my old 1.x MQTT config in OH, and these were my settings for an Sonoff Basic with ESPEasy:

device.items

Code: Select all

Switch Nano "Nano" <light> [ "Lighting" ]  {mqtt=">[mosquitto:Nano/gpio/12:command:ON:1.00],>[mosquitto:Nano/gpio/12:command:OFF:0.00],<[mosquitto:Nano/gpio/12:state:MAP(onoff.map)])", autoupdate="false"}
test.sitemap

Code: Select all

sitemap test label="test" {
Switch item=Nano
}

onoff.map

Code: Select all

0=OFF
1=ON
0.00=OFF
1.00=ON
OFF=0
ON=1

mqtt.cfg

Code: Select all

mosquitto.url=tcp://192.168.1.28:1883
mosquitto.clientId=openhab2
But if you're new to MQTT + OH, then I suggest to go for the new MQTT concept, as it brings a lot of advantages (plus stability) looking forward.

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 07 May 2019, 23:24
by mihai.icey.ro
It was from my OH2...:)).. I reinstalled the operation system and now it works..
What's the new mqtt? it's something much better than EasyEsp? I am a beginner in this thing and i want to learn more things :D

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 07 May 2019, 23:34
by mihai.icey.ro
I also have one more question.

It's possible to sink the EspEasy, relay state with OpenHab? Because if I switch the light on from the physical button i can't see it on the OpenHab if it's ON of OFF.

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 08 May 2019, 09:00
by mrwee
Use my example for switching on / off + getting status back from the device.

The new MQTT binding (https://www.openhab.org/blog/2018-12-16 ... cture.html) in openHAB brings the possibility of auto-discovery, increased stability and many other things. But for me the migration took a long time as it's configured completely differently. So if you're new to OH, I suggest to use the new concept and not the old.

I can provide you with examples for the new setup if you wish.

ESPEasy can stay as it it, not necessary to change anything there for basic MQTT.

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 08 May 2019, 13:26
by mihai.icey.ro
I would be more than happy if you can show me examples for the new setup. <3

Thanks a lot! <3

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 08 May 2019, 16:31
by mrwee
This is one of my switches, using the new format:

things file

Code: Select all

Thing topic TestLight "TestLight" @ "Test devices" {
	Channels:
		Type switch : command "Power Switch" [ commandTopic="TestLight/gpio/12", stateTopic="TestLight/Relay/Switch", on="1", off="0", autoupdate="false" ]
	}
items file

Code: Select all

Switch TestLight "Light" { channel="mqtt:topic:mosquitto:TestLight:command", channel="mqtt:topic:mosquitto:TestLight:state" }
ESP Easy device config:
2019-05-08_16-27-11.jpg
2019-05-08_16-27-11.jpg (76.04 KiB) Viewed 10722 times
the sitemap file is the same as before.

As a side note, I can highly recommend MQTT Explorer (https://mqtt-explorer.com/) for viewing your MQTT infrastructure. It shows your topics is a tree structure and can even show grahps :D

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 08 May 2019, 16:40
by mihai.icey.ro
Thank you very much! i will test with another ESP.

For the ESP i posted...i managed to make him to work...it was a problem in the OpenHab..yeeyy and now it works <3

it is a wat that i can send to OH2 the state of the relay?

This is the IF Code for switch

Code: Select all

on lightSwitch#Switch=1 do 
         if [lightState#Switch]=0 
              gpio,5,1
        else 
              gpio,5,0

        endif 

endon
on lightSwitch#Switch=0 do 
         if [lightState#Switch]=0 
              gpio,5,1
        else 
              gpio,5,0
         endif 
endon

Re: Espeasy and openhab - NEED HELP, PLEASE

Posted: 08 May 2019, 20:38
by mrwee
Your rule is only needed if you wish to switch the relay by button or other means. My examples take the published status coming from ESP Easy and updates your switch according to the status. If you enable "Interval" under the relevant device on ESP Easy and set it to e.g. 10 seconds, it will publish the current status constantly.