Openhab binding tasmota

openhab2
mqtt
items
Tags: #<Tag:0x00007f51db620c80> #<Tag:0x00007f51db620af0> #<Tag:0x00007f51db6209b0>

(Raul Vazquez) #1

I’ve been trying to bind a sonoff already flashed with the tasmota firmware.
im using mqtt.fx and i am able to comunicate with the sonoff publishing in the sonoff topic.
the problem is when im trying to turn it on with the openhab basic ui
the code im using in the item files is
Switch switch1 “Lamp” {mqtt=">[broker:cmnd/DVES_DF31A6_fb/POWER:command:ON:1],>[broker:cmnd/DVES_DF31A6_fb/POWER:command:OFF:0]"}


Openhab and Sonoff Switch
(Jürgen Baginski) #2

Which MQTT Binding are you using?
The item definition posted is using the syntax valid for MQTT Version 1, this is a legacy binding.
The current release version of openhab is coming with MQTT Version 2.
Version 2 has a complete different Setup, since it uses Things and Channels to which an item can be bound.

Documentation


(Raul Vazquez) #3

oh thank you for your answer im new in this, im using the mqtt broker 2.4
so in the things file i have to put this code?

mqtt:broker:myUnsecureBroker [ host="192.168.0.42", secure=false ]

instead of myunsecurebroke, can i choose any name?


(Hallo Ween) #4

You have to use a broker (maybe the included one from openhab like you already did) and the mqtt binding too.

Have you installed both?

Yes, you can choose the name of your broker by yourself.


(Raul Vazquez) #5

i have installed in the openhab the mosquitto file and in the binding section i have installed the mqtt broker 2.4.
also i have in my computer the mqttfx and when i conect it to the sonoff¨s topic i can control it and see his stats.


(Jürgen Baginski) #6

Reading the first post Here should help.


(Raul Vazquez) #7

i followed the both documentation and i still have some problems


this is the configuration i have in the channel

this is my code for the thing file:
Bridge mqtt:broker:Casa_Wayak [ host=“192.168.50.4”, secure=false ]
Thing Topic lampara “lampara”{
Type Switch :pool_lamp [ stateTopic=“stat/DVES_DF31A6_fb/power1” , commandTopic=“cmnd/DVES_DF31A6_fb/power1”, on=“ON”, off=“OFF”]
}
}
and this is my code for the item file
Switch SmartPool “lampara” {channel=“mqtt:topic:sonoff_lamp:power1”}


(Jürgen Baginski) #8

That could be the known issue of the 2.4 Version of the binding (already resolved in the snapshot version). Simply restart openhab without doing changes to the MQTT Setup.


(onacvooe) #9

I had the same problems setting up my sonof tasmota POWERSWITCH (Its not your lightbulb) I’ll post my configuration files here for reference…

In your story you are using MQTT.FX, with openhab2.4 it is not needed. My advise would be to remove it. And use the broker and MQTT of openhab himself…

BE SURE TO CONFIGURE A HOST IN YOUR SONOFF LIGHTBULB!!

CHECK THIS FIRST, OR ELSE IT WON’T CONNECT!

So my steps would be:

  1. Remove / Disable MQTT.FX.
  2. In PAPER UI go to Addons > Bindings
  • Install MQTT Binding.
  1. Still in Addons, go to Misc and search for: Embedded MQTT Broker
  • Install Embedded MQTT Broker
  1. The strong emphasised bits are explained. Now open a new file called bridge.things in your openhab things folder.
    and paste the following code into that and save:
Bridge mqtt:broker:wcd001bridge "wcd001bridge" @ "Woonkamer" [ 
  host="127.0.0.1",
  port=1883,
  secure=false,
  clientID="wcd001bridge"

mqtt:broker:wcd001bridge = a custom name, change to whatever you want.
"wcd001bridge" = a custom name and the label for this thing (not mandatory) change it to your likings.
"Woonkamer" = is a custom location, not mandatory and change it to what you want.

host = 127.0.0.1 | the same host as where openhab runs ons (i put in 127.0.0.1) because my system doesn’t like names. It likes IP addresses. :wink: This should also be 127.0.0.0.1 in your case.
port = 1883 | same story as host.
secure = false | same story as host.
clientid = wcd001bridge | can be anything but for the sake of keep it easy, keep it the same as the above names.

  1. Then open a new file called sonoff.things and past the following and save:
Thing mqtt:topic:wcd001 "Verlichting Woonkamer" (mqtt:broker:wcd001bridge) @ "Woonkamer"  {
  Channels:
    Type switch : PowerSwitch    "Lampen vensterbank" [ 
    	stateTopic="wcd001/stat/POWER",
    	commandTopic="wcd001/cmnd/power",
    	retained=true,
    	postCommand=true, 
    	on="ON",
    	off="OFF"											 ]

Allright, Now this part is going to be tricky but should be almost the same…
Keep in mind that I have a POWERSWITCH not a lightbulb, so I don’t know the differences. (if there are any)

Thing mqtt:topic:wcd001 (can be anything you like.)
"Verlichting Woonkamer" = A name/label of the thing (can be anything you like)
(mqtt:broker:wcd001bridge) must have the same name as the bridge we just configured above.(look in the bridge.things file for it).
"Woonkamer" = location of thing. (can be anything you want it to be).
Type switch : PowerSwitch = This probably is different with your lightbulb
"Lampen vensterbank" = a label/name (can be anything you want).
stateTopic & commandTopic , this might also be different with your lightbulb. Look in the configuration of your sonoff device under “configuration” > “Configure MQTT” > “Topic” and “Full Topic”. Under “Host” in the sonoff configuration put in the IP Address of the device that runs your Openhab installation.
retained, postCommand, on, off Not sure if it is needed in your case but if needed it should be the same.

Now the last thing sonoff.items, copy and paste

Switch wcd001_schakelaar 		  "Vensterbank voor" 	        { channel="mqtt:topic:wcd001:PowerSwitch" }

wcd001_schakelaar | wcd001 needs to be the same as your thing thats defined in sonof.things (mqtt:topic:wcd001)
schakelaar | can be anything you want it to be.
"Vensterbank voor" | is a label/name and can be anything you want.

Allright, this is my config, and this works with my powerswitch, hopefully your lightbulb will also work. If you want I could post my sitemap file and rule file also but its not needed to configure the sonoff device. Good luck!

IF you are using openHAB 2.4 and have installed MQTT binding and Embedded MQTT broker you could auto-configure the whole thing via the PAPER UI. It should be auto-discovered (mine did) and be sent to your inbox. But only after you put in the correct IpAddress in the host setting of your lightbulb config.

Good luck!


(Raul Vazquez) #10

thanks to all of you already is working


(Jürgen Baginski) #11

MQTTfx is not needed and never was, it is used as external MQTT client in order to see which messages are send. A MQTT broker is always needed.
When setting up MQTT it is always a good idea to be able to see the messages that are sent!


(onacvooe) #12

Ah yes, I wasn’t aware of that. Thank you @opus.
@Raevaz Nice to see it is working. Have fun!