ESP8266...openhab...mosquitto...MQTT...nightmare

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

ESP8266...openhab...mosquitto...MQTT...nightmare

#1 Post by vince59 » 05 Feb 2020, 18:43

As explained in another thread I am trying to get something working...but non success.
I really found all this flashing, configuring, openhabbing and other a nightmare :roll: :oops:
Able to flash ESPEasy, to have the GUI working...able to install openhab (I find this very very unfriendly and really complicated with command line).
But...I can not understand the way to move forward.
I started playing with openhab...I had things connected and working (Samsung TV). Now some questions:
1. How can I connect ESP8266 to openHab?
2. How to set the MQTT broker into openhab...no way to have mosquitto working.
3. How do I link openHab - mosquitto and the rest of the world?
4. I have 4 relay but I only see 2 on the espEasy GUI.
I hope someone can guide me....thanks for any help.
I wonder if it is really so complicated to have IoT working or I am going the wrong way.

TD-er
Core team member
Posts: 2792
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#2 Post by TD-er » 06 Feb 2020, 14:26

I don't have any experience with OpenHAB myself, but I do know a bit about MQTT.
First thing you have to check is if you have a MQTT broker running.
Not sure if OpenHAB includes one (probably not?), so you have to install one yourself.

The most frequently used one is Mosquitto.
So you need to install Mosquitto on some computer (makes sense to install it on the same as openHAB).
I guess OpenHAB must then also be told how to connect to this MQTT broker.

In ESPEasy you have to add a controller for OpenHAB MQTT and enter the same credentials (IP / user / pass) as you have configured in Mosquitto and OpenHAB to communicate with eachother.
Then you can select a controller from a task in ESPEasy (devices tab) and a task will then send data through this controller to MQTT and openHAB should also see those messages and act on it.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#3 Post by vince59 » 06 Feb 2020, 17:31

Thanks for the explanation.
So far I downloaded and installed Mosquitto. I am trying now to understand how to work with them.
I searched some guide over the web but no success.
I need to understand the basic principle of functioning to make it work...I am stopped at this point.

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

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#4 Post by ThomasB » 06 Feb 2020, 19:26

I searched some guide over the web but no success.
I need to understand the basic principle of functioning to make it work...I am stopped at this point.
It's been a few years since I went through the process of installing MQTT on OpenHAB. I've forgotten the installation details but fortunately there are many OpenHAB discussions and Youtube videos about doing it. So if you have not found any installation information then you should look again.

It's helpful to be aware how OH's MQTT has evolved over the years. My installation currently runs on a RPI3 with OH2.4 (haven't upgraded to OH2.5 yet). The original OH2.2 installation was setup with the Mosquitto broker and the MQTT1 Binding. I continued to use it as-is after upgrading to OH2.3. But when I upgraded to OH2.4 I had the option to use the new MQTT2 binding with the new Embedded Broker.

During the OH2.4 upgrade I decided to retain my legacy MQTT1 installation despite the promoted advantages of the MQTT2 binding. Here is a link explains the new features of the MQTT2 Binding.
https://www.openhab.org/blog/2018-12-16 ... cture.html

The reason for mentioning the two MQTT methods (legacy MQTT1 with Mosquitto broker Versus MQTT2 with Embedded broker) is because they use different installation instructions. And the usage examples you find online can be dependent on which one you are using. And most importantly, it is up to YOU to decide which binding and broker to use.

I did a quick search and found instruction examples for the legacy MQTT1 (with Mosquitto broker), plus a video for installing the new MQTT2 binding (with Embedded broker). So pick the MQTT setup you want to use and then install it:

OPTION 1 / Legacy MQTT1 Binding with Mosquitto broker:
https://www.smarthomeblog.net/mqtt-openhab/

OPTION 2 / MQTT2 Binding with Embedded broker (includes instructions to remove an existing Mosquitto broker):
https://www.youtube.com/watch?v=R-SrZvKHXdA

If these installation examples don't help you out then just do more searches for something better.

- Thomas

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#5 Post by vince59 » 08 Feb 2020, 10:27

Hey, thanks for your advice. I watched the video and some light at the end of the tunnel is seen. :D
I feel I am close to have it working.
I was able to use the embedded openhab broker, install and use MQTT fx and follow the video but I stopped where the guy sets the channel configuration in openhab.
In the video (time 11:55 to 12:05) he makes a local test (CMD panel?) then he takes some information from the screen and pastes these data into the openhab channel configuration panel.
Pasted data are MQTT command topic and MQTT status topic.
This step is confusing me as I do not understand what is he testing and how.
I assume it is the device but I did some test but no success.
Any hint abotu this?

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#6 Post by vince59 » 09 Feb 2020, 00:01

I am not able to configure the fuc... ESP8266 and the fuc... MQTT...WTF :evil: :evil: :evil: :evil: :evil:

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#7 Post by Micha_he » 09 Feb 2020, 11:03

Your post doensn't help anyone!

What operating-system, Linux or Windows? OpenhabianPi works perfectly for me.

What MQTT-Broker is currently running ?

Show us your ESPEasy controller settings. Maybe something is wrong there.

With mosquitto on linux: What do you get, when you execute the command 'mosquitto_sub -v -t /# | ts' in the shell and a ESPEasy-device with activated controller, change his value? See you the state topic?

Then we could take the next steps.

Sorry for my poor English, German is my first foreign language.

Micha.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#8 Post by vince59 » 09 Feb 2020, 13:05

Guten Tag Micha_he,
I know abotu my answer but I was disappointed it does not work. These are my first steps into IoT and I feel the software is not so friendly. Let me give you an overall view.
I simply started with a couple of ESP8266 and a 4 relays module (the module that comes with the ESP8266 bundled) that I made working over the wifi network...then I moved to the web, I aolso bought 2 nodeMCU and I succedeed to have them work through the Android APP available on the market. Then I relaized that you can do more and came to this great forum. My understanding is that it is possible to have ESP8266 working over the web using MQTT if flashed with dedicated firmware. I flashed ESPEasy and I was able to set up the ESP8266 and it working through ESPEasy GUI ( I can send command and actuate the relay). I aslso succedeed have the ESP working with MQTT APP. Now I would like to have the ESP8266 (later the nodeMCU and...raspBerry) working in a more integrated system.+ that the andorid APP does not offer (my feeling).
My understanding is that you can do it by:
- flashing ESP8266 (done)
- installing openHAB USING its embedded broker. I uninstalled Mosquitto.
I followed the video and tried to setup the system. I downloaded MQTT fx and it can publish...subscribe and so on.
But....I can not go forward. I was also able to control a Samsung TV with openhab but the TV has already some stock settings.
Going back to the video I do not understand how and where to get the MQTT state topic and command topic.
Am I doing mistakes in openHab or in ESP8266/ESPEasy settings?
Do I need Mosquitto or not?
I am using win 10 pro.
Vielen Danke for your help

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#9 Post by Micha_he » 09 Feb 2020, 14:38

If you've connected the ESP (controller & switch-device) with your MQTT-server, than your can simple switch (better with an event, but one step after the other) the GPIO witch publish the following with any MQTT-Client (local, smartphone,...):

/[espname case sensitive]/gpio/[nr] 1

for ON and to switch it OFF publisch:

/[espname case sensitive]/gpio/[nr] 0

Pay attention to the space, between topic and payload.
When this is working, you can integrate it to OpenHAB with the correct channel-config.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#10 Post by vince59 » 09 Feb 2020, 18:55

I believe I have NOT managed the connection between ESP and MQTT server.
I do not understand...do not know... the "concept".
I guess I do something wrong with Controller Subscribe: and Controller Publish: boxes in ESPEasy and channell setting MQTT State and Command Topic in Openhab.
I have quite confusion about this I am reading and reading but I find it very complicated.
Which pics you want me to publish to make you see what is the setting?

TD-er
Core team member
Posts: 2792
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#11 Post by TD-er » 09 Feb 2020, 19:30

Look at the Mosquitto settings, mainly at the port number.
What you need at first is to know the IP-address of the server Mosquitto is running on and also the port number.
The default port number is 1883 if I'm correct.
So for example your computer running Mosquitto has IP 192.168.1.10 and the ESP must have an IP in the same subnet (for example the first 3 numbers of the IP must be the same)

This will allow both to communicate with eachother.
When in doubt, try to ping the ESP from the computer running the MQTT broker.

If the ESP logs show you have a connection (Log level must be at least "INFO"), then we can discuss the topics you may need to subscribe to.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#12 Post by vince59 » 09 Feb 2020, 19:38

Hey TD-er,
I do not have Mosquitto installed as my understanding is that you can stay WITHOUT it if using embedded openhab broker.
The software (openhab) and the devices are in the same net. Openhab has port 1883.
Myabe this is a silly question...is the openhab IP the same as the broker?
BTW I fixed IP and checked ESPEasy log and it actually DOES connect to MQTT broker :|

TD-er
Core team member
Posts: 2792
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#13 Post by TD-er » 09 Feb 2020, 21:25

OpenHAB's own MQTT broker should also work.
So if that is running on the same computer as OpenHAB, then yes it should be the same IP address.

For ESPEasy there should be not much different between Mosquitto and OpenHAB's MQTT broker.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#14 Post by vince59 » 09 Feb 2020, 22:17

...well so far it seems it is ok. I have same IP and port in MQTT fx and ESPeasy setting.
ESPEasy log shows:
- connected to broker MQTT broker with client ID: xxxxx
- subscriberd to: xxxxxxx and so on.
MQTT fx shows connection and message transfer.
What now?
I still have some confusion about openhab MQTT State and Command Topic :?: I guess I have ESP to MQTT but NOT MQTT to/with OH.
I installed MQTT binding and Network binding in OH as I did not find any ESP8266 binding.
I am using MQTT binding and search for ESP8266 as Genericc MQTT thing.
Am I doing correct or not?

TD-er
Core team member
Posts: 2792
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#15 Post by TD-er » 10 Feb 2020, 11:35

I don't know OpenHAB myself, so there I cannot help you.
But just to give some general info on how MQTT does work.

MQTT uses "topics" which are structured just like folders in a file system.
You may post in topics and subscribe to topic to see what is posted there.
The nice part is that you can use wild cards in these subscriptions, which is represented by a #
So if things are a bit well structured in the topics, you can thus subscribe to a number of topics for your purpose. (e.g. only receive updates on switches or topics related to the same room as your node is in)

So what OpenHAB (and just any domotica related tool) does, is subscribe to all topics (or almost all) and process the messages posted in there.
It may also post messages in some topics, like "flip that switch".
Your ESPEasy node must therefore also subscribe to some topics to receive those updates.

This is hopefully making the concepts of MQTT brokers a bit more clear.
So now you have to check if OpenHAB also connects to the same broker and does subscribe to the topics you are using, or more likely, check that you are posting in the topics that OpenHAB expects to see messages in.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#16 Post by vince59 » 10 Feb 2020, 12:42

Thanks for the explanation...some doubts about what to do as these are my first step and I still have some "confusion" using proper terminology:
ESPEasy:
ESPEasy connects to broker. See following log message:
MQTT : Connected to broker with client ID: ESPClient_DC:4F:22:56:EA:6B
14394002: Subscribed to: LCTech/#
14394003: EVENT: MQTT#Connected


Question: it seems already subscribed the topic. Am I correct?

OpenHab:
You suggested to
"So now you have to check if OpenHAB also connects to the same broker and does subscribe to the topics you are using, or more likely, check that you are posting in the topics that OpenHAB expects to see messages in.
How do I check openhab connection and subscription in openhab?

Thanks

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#17 Post by Micha_he » 10 Feb 2020, 15:41

vince59 wrote:
10 Feb 2020, 12:42
Question: it seems already subscribed the topic. Am I correct?
Test it ! With MQTTfx publish: /[espname]/cmd relay,0,1

This should switch on relay1.
vince59 wrote:
10 Feb 2020, 12:42
How do I check openhab connection and subscription in openhab?
Maybe OpenHAB-Log or PaperUI (with binding V2.x)

Which MQTT-binding do you use in OpenHAB, 2.x or 1.x ? They use a different configuration. (so far my experience is based on V1.x)

With 2.x the following example/test could help:

Code: Select all

rule "MQTT_TEST"
when
    Time cron "0 */1 * ? * *" //every 1 Minute
then
  val actions = getActions("mqtt","mqtt:systemBroker:embedded-mqtt-broker")    // 2.parameter based on your thing/bridge-configuration
  actions.publishMQTT("test/system/started","true")
end

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#18 Post by vince59 » 10 Feb 2020, 17:40

Test with MQTT fx:
Config settings: broker address: local host (same machine ad OH)
broker port : 1883 (same as ...)
Suscribe: LCTech (ESP name)
Publish: LCTech into subscribed topic box (box with single line)
write message in the large box
/LCTech/cmd relay 1,1
press publish button.

No effect on the ESP relay module. However the black box in the subscribe page shows the message.
Log from MQTT fx as follows:

2020-02-10 17:33:23,554 INFO --- PublishController : publish
2020-02-10 17:33:23,555 INFO --- MqttFX ClientModel : attempt to add PublishTopic
2020-02-10 17:33:23,555 INFO --- MqttFX ClientModel : sucessfully published message /LCTech/cmd relay,1,5 to topic LCTech (QoS 0, Retained: false)
2020-02-10 17:33:23,592 INFO --- MqttFX ClientModel : messageArrived() with topic: LCTech
2020-02-10 17:33:23,593 INFO --- MqttFX ClientModel : messageArrived() added: message #1 to topic 'LCTech'


Question:
ESPEasy setting controller config:
- Controller Subscribe: %sysname/%
- Controller Publish: %sysname/%tskname%/%valname%

ESPEasy firmware as follows:

Build 20102 - Mega
Libraries ESP82xx Core 2_4_0, NONOS SDK 2.1.0(deb1901), LWIP: 2.0.3
GIT version (custom)
Plugins 11 [Normal]
Build Md5 4d44355f4d44355f4d44355f4d44355f
Build time Sep 20 2018 20:18:40
Binary filename ThisIsTheDummyPlaceHolderForTheBinaryFilename64ByteLongFilenames


Log from ESPeasy:

3291: Webserver: start
3383: MQTT : Intentional reconnect
3405: MQTT : Connected to broker with client ID: ESPClient_DC:4F:22:56:EA:6B
3407: Subscribed to: %LCTech/%
3409: EVENT: MQTT#Connected
3517: EVENT: LCTech#Relay0=0.00
3520: EVENT: LCTech#Relay1=0.00
3522: EVENT: LCTech#Relay2=0.00
3524: EVENT: LCTech#Relay3=0.00
3662: MQTT : Connection lost
3663: EVENT: MQTT#Disconnected
3680: MQTT : Connected to broker with client ID: ESPClient_DC:4F:22:56:EA:6B
3682: Subscribed to: %LCTech/%
3683: EVENT: MQTT#Connected


Is this correct?
Last edited by vince59 on 10 Feb 2020, 19:00, edited 1 time in total.

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#19 Post by Micha_he » 10 Feb 2020, 18:58

No,...

/LCTech/cmd

in publish and...

relay,1,1

in message box. No spaces !

TD-er
Core team member
Posts: 2792
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#20 Post by TD-er » 10 Feb 2020, 19:06

vince59 wrote:
10 Feb 2020, 17:40
Test with MQTT fx:
Config settings: broker address: local host (same machine ad OH)
broker port : 1883 (same as ...)
[...]
Are you absolutely sure it is localhost for MQTT fx?
Even when it is localhost, please try using the same IP-address as you are using in ESPEasy, just to be sure.

On what computer is the OpenHAB MQTT broker running?
On what computer are you running MQTT fx?
On what computer are you running OpenHAB?

What did you enter in OpenHAB where the MQTT broker should be? (hostname/IP + portnumber)

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#21 Post by vince59 » 10 Feb 2020, 19:17

Micha_he wrote:
10 Feb 2020, 18:58
No,...

/LCTech/cmd

in publish and...

relay,1,1

in message box. No spaces !
:mrgreen: Super Mein Freund IT WORKS!!!!!!!!!!!!!!!!! Alles Klar!!!!IN you are in the Munich area a beer for you!! (I lived four years in Germany and my daughter lives in Munich!)
One silly question....am I now controlling from my wifi or from the web (sorry about this question but I am still trying to digest the system architecture)
Last edited by vince59 on 10 Feb 2020, 19:22, edited 1 time in total.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#22 Post by vince59 » 10 Feb 2020, 19:21

TD-er wrote:
10 Feb 2020, 19:06
vince59 wrote:
10 Feb 2020, 17:40
Test with MQTT fx:
Config settings: broker address: local host (same machine ad OH)
broker port : 1883 (same as ...)
[...]
Are you absolutely sure it is localhost for MQTT fx?
Even when it is localhost, please try using the same IP-address as you are using in ESPEasy, just to be sure.

On what computer is the OpenHAB MQTT broker running?
On what computer are you running MQTT fx?
On what computer are you running OpenHAB?

What did you enter in OpenHAB where the MQTT broker should be? (hostname/IP + portnumber)
Dear Dutch friend...as you might have read. It works from the MQTT fx panel. I can switch relays on and off.
Now I am looking forward to have these controlled by OH.
PS: I was many times in th Nederlands as well :mrgreen:

Let me check and I will answer to your questions in a while

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#23 Post by vince59 » 10 Feb 2020, 19:37

Are you absolutely sure it is localhost for MQTT fx?
Even when it is localhost, please try using the same IP-address as you are using in ESPEasy, just to be sure.


Same IP-address (off course ESP8266 is another IP)

On what computer is the OpenHAB MQTT broker running?

Broker is OH Embedded one, so in my understanding it is runing "together with" OH in same PC;

On what computer are you running MQTT fx?

Same PC of OH

On what computer are you running OpenHAB?

Same.

What did you enter in OpenHAB where the MQTT broker should be? (hostname/IP + portnumber)
[/quote]

That is my problem. I do not really understand what to fill in.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#24 Post by vince59 » 10 Feb 2020, 20:30

double post
Last edited by vince59 on 10 Feb 2020, 20:39, edited 1 time in total.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#25 Post by vince59 » 10 Feb 2020, 20:32


Maybe OpenHAB-Log or PaperUI (with binding V2.x)

Which MQTT-binding do you use in OpenHAB, 2.x or 1.x ? They use a different configuration. (so far my experience is based on V1.x)

With 2.x the following example/test could help:

Code: Select all

rule "MQTT_TEST"
when
    Time cron "0 */1 * ? * *" //every 1 Minute
then
  val actions = getActions("mqtt","mqtt:systemBroker:embedded-mqtt-broker")    // 2.parameter based on your thing/bridge-configuration
  actions.publishMQTT("test/system/started","true")
end
[/i]

I do not follow this...sorry :roll: do I have to make a rule?...what then?

About MQTT binding question. I am using MQTT binding. I guess I need assistance to setup OH from scratch :roll: I tried form beginning but do not kow what item to select from MQTT binding...HOmie...NO....MQTT broker?....System MQTT Broker?....HA MQTT component...NO...Generic MQTT Thing? :?: :?:

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#26 Post by Micha_he » 11 Feb 2020, 09:26

vince59 wrote:
10 Feb 2020, 20:32
About MQTT binding question. I am using MQTT binding.
You haven't answered the MQTT-binding-version question yet. Look under 'Add-ons/Binding/MQTT-Binding...' Which version is installed on your OH ?
The configuration differs significantly !

Or mean 'MQTT binding' that you have installed version 2.5.1 ?

then we need your MQTT-Broker-bridge-configuration next. Take a look in OH 'Configuration/Things'. The bridge-definition is important. Something like 'mqtt:broker:xxxxx'. Today I've no time to test MQTT-Binding V2 at me, maybe tommorrow evening.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#27 Post by vince59 » 11 Feb 2020, 15:07

Micha_he wrote:
11 Feb 2020, 09:26
vince59 wrote:
10 Feb 2020, 20:32
About MQTT binding question. I am using MQTT binding.
You haven't answered the MQTT-binding-version question yet. Look under 'Add-ons/Binding/MQTT-Binding...' Which version is installed on your OH ?
The configuration differs significantly !

Or mean 'MQTT binding' that you have installed version 2.5.1 ?

then we need your MQTT-Broker-bridge-configuration next. Take a look in OH 'Configuration/Things'. The bridge-definition is important. Something like 'mqtt:broker:xxxxx'. Today I've no time to test MQTT-Binding V2 at me, maybe tommorrow evening.
Guten Tag,

MQTT Binding is 2.5.1

bridge (the only one I could choice): MQTT Broker - mqtt:systemBroker:embedded-mqtt-broker

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#28 Post by Micha_he » 11 Feb 2020, 16:38

On your OpenHAB-WinPC must exists a folder for OpenHAB config files. The subfolder things,items,rules,.... should be in it.
Look in the 'things'-subfolder for your mqtt-bridge-thing (it should begin with: 'bridge mqtt:systemBroker:embedded-mqtt-broker') and show us the complete content. So we can see, if things already exist there.

But all without the new binding being installed on my OpenHAB server! It's a little different here on my Raspi-server.

The next steps:
- you need at least one (can be splitted in seperate thing-files) thing(-file) with bridge to your MQTT and at least one thing (your LCTech-device)
- then you need a item(-file) with channels for state and command to your relay.

Look for some examples here: https://github.com/eclipse/smarthome/bl ... /README.md

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#29 Post by Micha_he » 11 Feb 2020, 17:57

Correction: The examples are OK, but config-files are not created, when use the OH-web-interface to create things and so on.
My private configuration is via txt-files :-(

Have you configured the broker(-thing) via web-interface or via textfiles?

Correct, you've a thing like 'MQTT broker' and this thing is online?

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#30 Post by vince59 » 11 Feb 2020, 23:29

Micha_he wrote:
11 Feb 2020, 17:57
Correction: The examples are OK, but config-files are not created, when use the OH-web-interface to create things and so on.
My private configuration is via txt-files :-(

Have you configured the broker(-thing) via web-interface or via textfiles?

Correct, you've a thing like 'MQTT broker' and this thing is online?
I created with OH-web innterface so no files.
I have a thing MQTT broker and it is ONLINE. Broker ID is embedded-mqtt-broker
I also have a thing named LCTech and it is ONLINE. Bridge is: MQTT Broker - mqtt:systemBroker:embedded-mqtt-broker. It is a Genereic MQTT Thing with mqtt:topic:7263475c.

So I believe it should be fine.

What I am not able to do or better I keep reading and I get more confusion in my head is to set up is the fuc... channels. I guess I need four channels for rel 1, rel 2 and so on.

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#31 Post by Micha_he » 12 Feb 2020, 09:19

I've done it here, but only the first half...

Create a switch-item (if you haven't done it yet), name it e.g. LCTechRel1 and set autoupdate to enforce (currently I've no solution to get the real state).

Create (or edit if you've already created one) a channel under your LCTech-Thing, type 'on/off-switch', give it an identifier and a label. Set the command-topic to '/LCTech/cmd' (let the state-topic empty for now), custom on-value to 'relay,0,1' and custom off-value to 'relay,0,0'. Save it.

Click on the blue circle from the created channel and select the created item from above (e.g. LCTechRel1) and click 'link'.

Test the item under OpenHAB/Control... I hope I didn't forget anything...

But I've no solution to get the real state, if I switch it from another way like ESPEasy-Webinterface.
State topic (e.g. '/LCTech/[devicename]/[valuename1]') can get the values 0 or 1. That differs from the command payload 'relay,0,[0/1]'. The 'Outgoing Value Format' in the channel doesn't work in my tests.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#32 Post by vince59 » 12 Feb 2020, 15:03

Hey Micha_he,

super! It works. I have the control panel working and now it is quite clear to me what/where to write and this is very important for better understanding of the whole system.
I had to remove the "/" at the beginning of the MQTT Command Topic

Next step is to control from the internet.

Vielen Danke for your help! and thank all of you that helped me to understand!

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#33 Post by Micha_he » 12 Feb 2020, 15:16

vince59 wrote:
12 Feb 2020, 15:03
I had to remove the "/" at the beginning of the MQTT Command Topic
Maybe because I use mosquitto-MQTT on OpenHAB !?

The simplest, but unsecure way is: Portforwarding the OpenHAB-port in your router, setup DynDNS and use the OpenHAB-App on Android/IOs.
In a second step a little more security with 'nginx'-proxy (for authorization) on your OpenHAB-server.
Last edited by Micha_he on 12 Feb 2020, 15:25, edited 1 time in total.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#34 Post by vince59 » 12 Feb 2020, 15:25

Thanks I will give it a try...free beer for you in Munich!!! :mrgreen:

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#35 Post by Micha_he » 12 Feb 2020, 15:30

600km is too far for a beer :P

Maybe I find a way, to get the real state (? four values from your ESPEasy-LCTech-device) ? I'll have a look...
We will probably need a MAPPING for that.

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#36 Post by Micha_he » 12 Feb 2020, 18:19

To get the real state back, you change the following:

1. Switch the relay_x-item to 'veto an auto update'
2. Create a file 'relay0.map' (you need a seperate for each relay-command) in the 'transform' subfolder of your OH-installation. Maybe with linux linefeeds !? with the following content:

Code: Select all

OFF=Relay,0,0
ON=Relay,0,1
0=OFF
1=ON
3. Change the relay_x-channel from your LCTech-thing as follows:
- set state-topic to 'LCTech/[ESP-Serial MCU controlled switch-devicename]/[name of 1. value of the device for relay0]
- let command-topic how it was
- set custom-on-value to 'ON' (it seems OH 2.5.1 otherwise sends an empty string)
- set custom-off-value to 'OFF' (secure, see above)
- set incoming and outgoing value transformation to 'MAP:relay0.map' (1-3 for the other relays, because of the changed command)
- save it
4. Switch your relay from web-IF an look at OH/control

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#37 Post by vince59 » 12 Feb 2020, 20:43

Micha, I can't follow you right now. I have to understand what you mean on the practical side.
If I am correct you want to monitor the actual state of the relays. Am I correct?
So far I ma very satisfied the system is working and I get a grip on the procedure and how the system works.
I believe openHAB is great as it allow you to control devices from diferent type and brands.
My understanding is that the PC running OH MUST be always switched on, so I believe I will eventually end up using raspberry.

Micha_he
Normal user
Posts: 148
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#38 Post by Micha_he » 13 Feb 2020, 09:11

vince59 wrote:
12 Feb 2020, 20:43
If I am correct you want to monitor the actual state of the relays. Am I correct?
Yes, that's what I mean. If you change the state from outside of OH (maybe a restart from your LCTech-relay), then OH may show the wrong state :!: :?: :(

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#39 Post by vince59 » 13 Feb 2020, 10:30

Very nice option. After initial frustration I feel quite enthusiast about OH.
I am trying to understand what would be best hardware setup for my project IoT. It is a small project with 4/5 switches and some sensors.
I realized thet it is a MUST to have a pc always running OH so I am looking at raspberry solution. I wonder if there is an alternative solution.
I will study your suggestions and will try to integrate into the system for better understanding and improve my knowledge.

Tschuss

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#40 Post by vince59 » 13 Feb 2020, 15:21

Micha_he wrote:
12 Feb 2020, 18:19
1. Switch the relay_x-item to 'veto an auto update'
2. Create a file 'relay0.map' (you need a seperate for each relay-command) in the 'transform' subfolder of your OH-installation. Maybe with linux linefeeds !? with the following content:

Code: Select all

OFF=Relay,0,0
ON=Relay,0,1
0=OFF
1=ON
3. Change the relay_x-channel from your LCTech-thing as follows:
- set state-topic to 'LCTech/[ESP-Serial MCU controlled switch-devicename]/[name of 1. value of the device for relay0]
- let command-topic how it was
- set custom-on-value to 'ON' (it seems OH 2.5.1 otherwise sends an empty string)
- set custom-off-value to 'OFF' (secure, see above)
- set incoming and outgoing value transformation to 'MAP:relay0.map' (1-3 for the other relays, because of the changed command)
- save it
4. Switch your relay from web-IF an look at OH/control
Hey, nice test...but...I did everything (including 3 .map file - one for each realy, but I am not sure about the results. It is somehow illogical to me.
I made the test using android app
What was the intent of the test..what should I expect?
- Icon switching colour?
- indication ON or OFF close to the panel switch?
- update of the web IF control?.
State topic as follows: LCTech (name on device) / LCTech (again as this is the name of the MCU) / Relay0 (as this is the # Name of item number 1 in the device properties)
I compiled the .map file with notepad and I filled the line as follows: MAP:relay0.map
In every case the relays were correctly working but I have to check the consistency between logic state and icons/switches. One strange weird thing...with the same setting for all the channels I have no display of the ON - OFF state indication in the app panel for the first relay. The other do have the indication ON OFF properly working.

vince59
Normal user
Posts: 30
Joined: 30 Jan 2020, 21:41

Re: ESP8266...openhab...mosquitto...MQTT...nightmare

#41 Post by vince59 » 14 Feb 2020, 15:20

I did several tests and to get some practice I did everything from the beginning.
I added MQTT state topic and MAP files.
APP activates switches and shows icon and switch changing color/state and ON/OFF indication.
WEB gui changes switch position accordingly. Only weird thing is that the rel 1 (relay0) does not show ON/OFF indication.
Channels and switches were create in the same way.
I wonder what happens as I guess this is not the proper way.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 18 guests