Sonoff 4ch Pro 2 / Tasmota & OpenHAB

Tags: #<Tag:0x00007f6173ec1478> #<Tag:0x00007f6173ec13b0>

Hi,

I got two sonoffs 4 ch pro ver 2. The flashing to TASMOTA is completed.
Since two days I tried to connect these two sonoffs to OPENHAB.
It doesn´t work.
Exists a step-by-step tutorial for this? I found some for the sonoff power. In some tutorials some use mosquitto as iobroker and some are telling that in the new version of OPENHAB a broker is included.
I am a totally beginner and so I hope to find a step by step tutorial or help to get the 4ch pro connected.

Actual I have installed:

_Services. mqtt broker
_Things I tried to install a mqtt thing

but I know that my configuration is wrong.
What I have to do to connect tasmota mqtt with openhab?

What I want to do with openhab is to schedule valves for my little garden (irrigation).
The magnetic valves should open and close at a scheduled plan.
This is possible with tasmota also but this should be the first step because I have some more smart things linke HUE, ALEXA …

Thanks.

Regards
Peter

Welcome Peter!

I would recommend installing Mosquitto. Once installed, ensure your Tasmota device MQTT settings point to Mosquitto.

Then, download either MQTT.fx or MQTT Explorer and check to make sure that MQTT messages are being sent/received. You can do this by activating the relays through the Tasmota UI, and watching what the MQTT software reports.

Then you’re ready to integrate with openHAB. We can help with that bit. Just be aware that the MQTT binding is currently V2, but there are a lot of older examples online using the V1 binding.

Thank you for the advice.
But where can I find the statements I have to use for test?
I am confused… I have installed mosquitto on windows. But how do I set it correctly up? There are so many tutorials for rasperry and/or ubuntu but windows neither.
And sonoff 4ch pro ver2 and openhab I found nothing.

To test Tasmota with mosquitto and mosquitto.fx I need the correct Tasmota config first.
Which name I need in the MQTT config - Topic and Fulltopic? Mosquitto and openhab are installed on a mini PC with win 10 pro.
So mosquitto and openhab are on the same machine. Is that configuration possible or do I need a seperate machine?
In Tasmota I only can set a “host”…

Concentrate on getting the MQTT stuff working first; only then turn to openHAB.

Follow the instructions in the Tasmota documentation. In short:

  • Enable MQTT
  • Host: IP address of your computer that is running Mosquitto
  • Client: unique name for your device - let’s use 4chPro2 for now
  • Topic: 4chPro2

Leave everything else as default.

Now, using MQTT.fx, send an ON message to the following topic:

cmnd/4chPro2/POWER1

I think this should switch on the first relay. If that doesn’t work, using the Tasmota web interface to toggle the relay on and off, and then go into the Tasmota web interface Console and see what commands where sent.

Tasmota documentation. But that’s quite a list: just use the Tasmota web interface buttons first, and see what the result is on the Tasmota web interface Console.

I haven’t used it on Windows so can’t answer this myself, unfortunately. For me, there was no configuration required after setup.

Yes, it’s fine for both to be on the same machine. But again, concentrate on understanding and getting MQTT setup before moving to openHAB.

Have you looked at using tasmotizer?

Ok. Thank you
I tried as as you wrote
But… Nothing happens.
I tried to submit the cmnd but the sonoff doesn’t power on…

Where I have to send the command? In the scripts section? I tried all :frowning:nothing happens

Can you confirm how you tried to submit the command?

Did you also try this?

I’ve installed one 4chpro2 recently and I had similar doubts.

The very first thing is to test if sonoff reacts to the web interface. Are you able to Toggle each switch ?

2nd you need to install a mosquitto broker. It can be the one provided by OpenHab or another one. I use another one but the OH supplied broker should be ok. Take a note of its userid, password, IP address and port.

3rd it’s time to install MQTT.fx (in Windows) and login it to the MQTT broker. If this is Ok then you have a working MQTT broker.

4th you need to go to the sonoff web interface and parametrize MQTT credentials. In my case it is

5th go to MQTT.fx, connect and then subscribe #
If the sonoff is parametrized correctly you should see what mqtt messages it is producing. Take a note of the ones suffixed POWERn that have stat in the middle. This string is used by the sonoff to report the status of each switch. To control the switch the same string is used, replacing stat by cmnd, and supplying a value (On or Off). You can use MQTT.fx to send these commands and see in sonoff’s web interface if the switches change to the requested state.

6th, install the MQTT binding in OpenHab, and login it to your MQTT broker. If this is Ok you will see it online in Paper UI

7th, using the OH documentation, create the things and items to control the sonoff’s.

OK. thanks …
1 goal is reached
Now I get STATE information but I couldn´t publish- cmnd/4chPro2/POWER1 do not work…

This is the Tasmota config

Whats the difference between TOPIC, FULL TOPIC and CLIENT? Which of them I need for MQTT?

Ich have two identical sonoffs 4 ch - so if I get this running I have to connect the 2nd also

And here MQTT.fx

But only subscribe

Do I need to do all commands case sensitive???

I only said to change user client and topic. You need to leave full topic as default, otherwise my other examples won’t work.

And yes, everything is case sensitive.

Edit:

My apologies, you should change the value of client, not user. Below are the settings you could use for your two devices, 4chPro2-1 and 4chPro2-2.

Device setup

Device 1: 4chPro2-1

Alter only Host, Client and Topic. The screenshot below is what you should end up with.

Device 2: 4chPro2-2

Alter only Host, Client and Topic. The screenshot below is what you should end up with.

MQTT Check

Now, using mqtt.fx publish the word ON to the following topic. This should switch on the first relay on the first device:

cmnd/4chPro2-1/POWER1

I don’t use mqtt.fx, but do use MQTT Explorer. In MQTT Explorer, I would:

  1. Type the topic into the Topic field: cmnd/4chPro2-1/POWER1
  2. Set type to raw
  3. Write ON into the message field
  4. Click PUBLISH

image

For the second relay on the first device, publish the word ON to:

cmnd/4chPro2-1/POWER2

For the first relay on the second device, publish the word ON to:

cmnd/4chPro2-2/POWER1

And so on. To turn those relays off, publish the word OFF to each topic.

Once you have confirmed that you are able to control your device through mqtt.fx, you can move on to configuring openHAB. Do not move onto the next stage until the above works.

openHAB setup

These examples show how to configure using files: things files, items files and sitemap files. You can configure the thing through paperUI, but it’s much easier just to copy/paste into a file, than to share screenshots! The below also assumes you haven’t set anything up in openHAB yet - if you have, there may be strange results if you use the below.

mosquitto.things

Save a file called mosquitto.things into your openHAB things folder with the following inside. If you have not setup a username or password, leave the below as it is - otherwise, add your username and password between the " ":

Bridge mqtt:broker:MosquittoMqttBroker "Mosquitto MQTT Broker" [
	host="192.168.1.92",
	secure=false,
	port=1883,
	clientID="OpenHAB2",
	username="",
	password=""
]

openHAB now has a connection to your Mosquitto broker!

devices.things

Save a file called devices.things into your openHAB things folder with the following inside:

Thing mqtt:topic:4chPro2-1 "Device 1" (mqtt:broker:MosquittoMqttBroker) {
	Channels:
		Type switch:relay1 "Relay 1" [
			stateTopic="stat/4chPro2-1/POWER1",
			commandTopic="cmnd/4chPro2-1/POWER1",
			on="ON",
			off="OFF"
		]
		Type switch:relay2 "Relay 2" [
			stateTopic="stat/4chPro2-1/POWER2",
			commandTopic="cmnd/4chPro2-1/POWER2",
			on="ON",
			off="OFF"
		]
		Type switch:relay3 "Relay 3" [
			stateTopic="stat/4chPro2-1/POWER3",
			commandTopic="cmnd/4chPro2-1/POWER3",
			on="ON",
			off="OFF"
		]
		Type switch:relay4 "Relay 4" [
			stateTopic="stat/4chPro2-1/POWER4",
			commandTopic="cmnd/4chPro2-1/POWER4",
			on="ON",
			off="OFF"
		]

Thing mqtt:topic:4chPro2-2 "Device 2" (mqtt:broker:MosquittoMqttBroker) {
	Channels:
		Type switch:relay1 "Relay 1" [
			stateTopic="stat/4chPro2-2/POWER1",
			commandTopic="cmnd/4chPro2-2/POWER1",
			on="ON",
			off="OFF"
		]
		Type switch:relay2 "Relay 2" [
			stateTopic="stat/4chPro2-2/POWER2",
			commandTopic="cmnd/4chPro2-2/POWER2",
			on="ON",
			off="OFF"
		]
		Type switch:relay3 "Relay 3" [
			stateTopic="stat/4chPro2-2/POWER3",
			commandTopic="cmnd/4chPro2-2/POWER3",
			on="ON",
			off="OFF"
		]
		Type switch:relay4 "Relay 4" [
			stateTopic="stat/4chPro2-2/POWER4",
			commandTopic="cmnd/4chPro2-2/POWER4",
			on="ON",
			off="OFF"
		]

openHAB can now communicate with the device through the MQTT broker.

devices.items

Save a file called devices.items into your openHAB items folder with the following inside:

Switch sDevice1Relay1 "Device 1 Relay 1"  { channel="mqtt:topic:4chPro2-1:relay1" }
Switch sDevice1Relay2 "Device 1 Relay 2"  { channel="mqtt:topic:4chPro2-1:relay2" }
Switch sDevice1Relay3 "Device 1 Relay 3"  { channel="mqtt:topic:4chPro2-1:relay3" }
Switch sDevice1Relay4 "Device 1 Relay 4"  { channel="mqtt:topic:4chPro2-1:relay4" }

Switch sDevice2Relay1 "Device 2 Relay 1"  { channel="mqtt:topic:4chPro2-2:relay1" }
Switch sDevice2Relay2 "Device 2 Relay 2"  { channel="mqtt:topic:4chPro2-2:relay2" }
Switch sDevice2Relay3 "Device 2 Relay 3"  { channel="mqtt:topic:4chPro2-2:relay3" }
Switch sDevice2Relay4 "Device 2 Relay 4"  { channel="mqtt:topic:4chPro2-2:relay4" }

openHAB has now got some items connected to your things channels. We can now manipulate these items using the sitemap or rules.

sitemap

In your sitemap file, add the following:

Switch item=sDevice1Relay1 label="Device 1 Relay 1 [%s]"
Switch item=sDevice1Relay2 label="Device 1 Relay 2 [%s]"
Switch item=sDevice1Relay3 label="Device 1 Relay 3 [%s]"
Switch item=sDevice1Relay4 label="Device 1 Relay 4 [%s]"

Switch item=sDevice2Relay1 label="Device 2 Relay 1 [%s]"
Switch item=sDevice2Relay2 label="Device 2 Relay 2 [%s]"
Switch item=sDevice2Relay3 label="Device 2 Relay 3 [%s]"
Switch item=sDevice2Relay4 label="Device 2 Relay 4 [%s]"

Your sitemap should now show you 8 switches, which you should be able to toggle on and off!