Sonoff Tasmota Link to openHAB

Apologies, I was doing this from the wrong directory. I’m back up to my orginial stage now.

I’ve also changed the icon on the button so now read:

Switch GarageDoor "Garage Door" <light> { mqtt=">[mqttoh:cmnd/garageDoor/POWER:command:*:default], <[mqttoh:stat/garageDoor/POWER:state:default]" }

You have access to the UI and have changed the addons.cfg to original/default with everything working?

If so I advise to make a backup now as well as anytime you make big changes.

From terminal type: sudo openhab-cli backup
This will place a backup zip in /var/lib/openhab2/backups
Move the zip file to your PC or some other device. To restore the backup put the zip file back into /var/lib/openhab2/backups and do the following:

sudo systemctl stop openhab2.service

openhab-cli restore /var/lib/openhab2/backups

sudo systemctl start openhab2.service

1 Like

Your conf. on tasmota firmware is?

1 Like

Hi, Thank you all for your help. I have managed to get Tasmota and openHab working together.

The next thing I’d like to do is add a reed switch which i have done. Setting GPIO14 to Switch2. I’ve set the Switchtopic to ‘garageDoorSensor’ and SwitchMode2 ‘1’ and finally SwitchRetain ‘on’.

I can see the reed switch opening and closing in the Tasmota console:

18:41:08 MQT: cmnd/garageDoorSensor/POWER2 = ON (retained)
18:41:10 MQT: cmnd/garageDoorSensor/POWER2 = OFF (retained)
18:41:43 MQT: cmnd/garageDoorSensor/POWER2 = ON (retained)
18:41:45 MQT: cmnd/garageDoorSensor/POWER2 = OFF (retained)

I’ve also added the contact to .items:
// GarageDoorSensor
Contact GarageDoorSensor “Garage Door Sensor” { mqtt="<[mqttoh:cmnd/garageDoorSensor/POWER2:state:default]" }

However, this is not doing anything. I do see the below in tail:
2018-08-20 18:49:54.606 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'GarageDoorSensor'

Any ideas what I’m doing wrong here?

In addition in terminal i can subscribe to the GarageDoorSensor and works:

[18:55:58] openhabian@openHABianPi:~$ mosquitto_sub -h localhost -t "+/garageDoorSensor/#" -v
cmnd/garageDoorSensor/POWER2 OFF
cmnd/garageDoorSensor/POWER2 ON
cmnd/garageDoorSensor/POWER2 OFF
cmnd/garageDoorSensor/POWER2 ON
cmnd/garageDoorSensor/POWER2 OFF

Any help would be greatly appreciated! :grinning:

You have the carrot symbol pointing in the wrong direction for a command.

Needs to be mqtt=">[

1 Like

Hi, Thanks for your reply.

I have done this but receving the below error:

[ERROR] [el.item.internal.GenericItemProvider] - Binding configuration of type 'mqtt' of item 'GarageDoorSensor' could not be parsed correctly.

org.eclipse.smarthome.model.item.BindingConfigParseException: Configuration 'mqttoh:cmnd/garageDoorSensor/POWER2:state:default' is not a valid outbound configuration: Configuration requires 5 parameters separated by ':'

Any ideas?

The log tells you the answer…You need 5 parameters.

Try with the star between command (not state) and default like below

mqttoh:cmnd/garageDoorSensor/POWER2:command:*:default'
1 Like

Not getting an error, now getting a warning. However, still not working…

2018-08-20 21:35:54.750 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/GarageDoorSensor' with an invalid status value 'ON'.

2018-08-20 21:35:55.460 [WARN ] [rest.core.internal.item.ItemResource] - Received HTTP POST request at 'items/GarageDoorSensor' with an invalid status value 'OFF'.

NOTE: this doesnt always appear :expressionless:

Probably, because it will occur only when the 2 values of the same item are different. Test it by turning both on and off while watching the log. Then turn only one on and see what the log say’s.

EDIT: I had to go back and look at what your doing with the sonoff and GPIO14.

My fault for not rereading all the post and only responding to this error. You really need to read about sonoff. mqtt, and OH. You have an item as a contact not a switch, with a mqttoh:cmnd . So the carrot was correct the first time but your mqtt config was and still is wrong. A contact might tele or stat (hint,hint) you the state (hint,hint) of the contact, but it’s not used to send a command.

READ the Tasmota Wiki

You have all the puzzle pieces, just need to find where they fit.

1 Like

Hi,
Thanks for this, I’ve been reading the wiki and even other examples. Currently i have the following:

.items:
Contact GarageDoorSensor "Garage Door Sensor [%s]" { mqtt="<[mqttoh:stat/garageDoorSensor/POWER2:state:default]" }

.sitemap:
sitemap home label=“Home” {

        Frame label="Garage" {
                Switch item=GarageDoor
                Text  item=GarageDoorSensor
        }
}

With the above, i get no errors or logs. According to the wikis and examples the above should be correct…

I must be doing something silly here…

any help from anyone would be most helpful :slight_smile:

Go to your Sonoff WebUi and click on Console. You should see the logs in real time. While watching the log, make and break the contact. This will show the output that you need to use in your OH items file.

1 Like

Hi, I’ve done this and looks like below in the Sonoff WebUi:

19:29:12 MQT: cmnd/garageDoorSensor/POWER2 = OFF
19:29:14 MQT: cmnd/garageDoorSensor/POWER2 = ON
19:29:17 MQT: cmnd/garageDoorSensor/POWER2 = OFF
19:29:19 MQT: cmnd/garageDoorSensor/POWER2 = ON
19:29:22 MQT: cmnd/garageDoorSensor/POWER2 = OFF
19:29:23 MQT: cmnd/garageDoorSensor/POWER2 = ON
19:29:26 MQT: cmnd/garageDoorSensor/POWER2 = OFF
19:29:30 MQT: cmnd/garageDoorSensor/POWER2 = ON
19:29:34 MQT: cmnd/garageDoorSensor/POWER2 = OFF

In the openHAB trail i get the below:

2018-08-21 19:31:36.655 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'GarageDoorSensor'

2018-08-21 19:31:37.450 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'GarageDoorSensor'

2018-08-21 19:31:37.750 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'GarageDoorSensor'

2018-08-21 19:31:39.352 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'GarageDoorSensor'

2018-08-21 19:31:40.402 [WARN ] [b.core.events.EventPublisherDelegate] - given new state is NULL, couldn't post update for 'GarageDoorSensor'

So it looks like openHAB can see the trigger but doesnt know what to do with it?

Switch GarageDoor "Garage Door" <light> { mqtt=">[mqttoh:cmnd/garageDoor/POWER:command:*:default], <[mqttoh:stat/garageDoor/POWER:state:default]" }

Your original item that works, correct?

What happens if you add this item.

Contact garageDoorSensor "Garage Door Sensor" <light> { mqtt="<[mqttoh:stat/garageDoor/POWER2:state:default]" }
1 Like

Yes, the orginal item works correctly! If i do the above i get nothing in the trail :frowning:

You can change the item from “Contact” to Switch or change your sitemap config to match the Contact.

At this point it may be best if you only change the Item name ( contact ) leave everything else alone and test it.
Like this, I also changed the light to switch between the carrots.

Switch garageDoorSensor "Garage Door Sensor" <switch> { mqtt="<[mqttoh:stat/garageDoor/POWER2:state:default]" }
1 Like

It works as a Switch!! :smiley:

Not sure why it doesnt work as a contact?

Because either, you have not read the documentation or you do not understand the documentation.

You can use Contact, but a MAP will be needed because OH looks for an Open/Closed state of contact and the sonoff is sending ON and OFF, hence the error.

1 Like

You keep telling @Jeevs to read the documentation better while at the same time giving wrong advice. Maybe don’t speak so firmly if you’re not sure what is going on. You added a lot of confusion to the situation.

@Jeevs, you have done better than most newbies I’ve seen at wading through the errors and understanding what’s going on. Good job!

The reason why it didn’t work as a contact is because the sonoff device was sending ON and OFF as values while the contact item type needs OPEN and CLOSED as values. A switch expects exactly the values that sonoff is sending which is why that worked. To use a contact you would need to replace the “default” portion of your item configuration with a transformation that converts from ON/OFF to OPEN/CLOSED. You would use the Map transformation type since this is a simple one to one replacement.

Another thing to note is that the client id discussed at the beginning of the thread should be unique for each device they connects to mqtt. If you set client id in openhab to the same value as client id in tasmota, one of the two devices will get kicked off the server. This is why you were seeing connects and disconnects in the log. Once you commented out that line, openhab was able to pick its own unique client ID and the devices stopped kicking each other off the mqtt server.

You are correct and I apologize for some of the confusion. On a few replies, it would have been better to re-read all the post before making a reply. My intent was to point Jeevs toward finding the solution, not just providing the answer. Yes, Jeevs did well and I hope now he has a better understanding of the error messages, how to troubleshoot, and solve problems.

Would be a nice feature to have something like a live face chat to help with communication in both directions.:smile:

So true. It can be very easy to miss stuff or explain unclearly in written communication. Glad it all got figured out in the end!