Espeasy and openhab - NEED HELP, PLEASE

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
mihai.icey.ro
Normal user
Posts: 15
Joined: 01 May 2019, 00:24

Espeasy and openhab - NEED HELP, PLEASE

#1 Post by mihai.icey.ro » 06 May 2019, 21:16

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

User avatar
ThomasB
Normal user
Posts: 1214
Joined: 17 Jun 2018, 20:41
Location: USA

Re: Espeasy and openhab - NEED HELP, PLEASE

#2 Post by ThomasB » 06 May 2019, 23:05

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

mihai.icey.ro
Normal user
Posts: 15
Joined: 01 May 2019, 00:24

Re: Espeasy and openhab - NEED HELP, PLEASE

#3 Post by mihai.icey.ro » 07 May 2019, 07:34

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

s0170071
Normal user
Posts: 36
Joined: 21 Oct 2017, 20:49

Re: Espeasy and openhab - NEED HELP, PLEASE

#4 Post by s0170071 » 07 May 2019, 09:21

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.

mrwee
Normal user
Posts: 225
Joined: 31 Aug 2016, 12:52

Re: Espeasy and openhab - NEED HELP, PLEASE

#5 Post by mrwee » 07 May 2019, 20:34

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

mrwee
Normal user
Posts: 225
Joined: 31 Aug 2016, 12:52

Re: Espeasy and openhab - NEED HELP, PLEASE

#6 Post by mrwee » 07 May 2019, 21:23

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.

mihai.icey.ro
Normal user
Posts: 15
Joined: 01 May 2019, 00:24

Re: Espeasy and openhab - NEED HELP, PLEASE

#7 Post by mihai.icey.ro » 07 May 2019, 23:24

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

mihai.icey.ro
Normal user
Posts: 15
Joined: 01 May 2019, 00:24

Re: Espeasy and openhab - NEED HELP, PLEASE

#8 Post by mihai.icey.ro » 07 May 2019, 23:34

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.

mrwee
Normal user
Posts: 225
Joined: 31 Aug 2016, 12:52

Re: Espeasy and openhab - NEED HELP, PLEASE

#9 Post by mrwee » 08 May 2019, 09:00

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.

mihai.icey.ro
Normal user
Posts: 15
Joined: 01 May 2019, 00:24

Re: Espeasy and openhab - NEED HELP, PLEASE

#10 Post by mihai.icey.ro » 08 May 2019, 13:26

I would be more than happy if you can show me examples for the new setup. <3

Thanks a lot! <3

mrwee
Normal user
Posts: 225
Joined: 31 Aug 2016, 12:52

Re: Espeasy and openhab - NEED HELP, PLEASE

#11 Post by mrwee » 08 May 2019, 16:31

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 12850 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

mihai.icey.ro
Normal user
Posts: 15
Joined: 01 May 2019, 00:24

Re: Espeasy and openhab - NEED HELP, PLEASE

#12 Post by mihai.icey.ro » 08 May 2019, 16:40

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

mrwee
Normal user
Posts: 225
Joined: 31 Aug 2016, 12:52

Re: Espeasy and openhab - NEED HELP, PLEASE

#13 Post by mrwee » 08 May 2019, 20:38

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.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 3 guests