Sonoff Tasmota Link to openHAB

  • Platform information:
    • Hardware: RaspberryPI 3 Model B+
    • OS: Openhabian
    • openHAB version: Latest

A big hello to the community!

I am a newbie with openHAB so please excuse any silly questions. I have successfully setup openhabian on my Raspberry Pi 3 B+ having also installed Mosquitto as my MQTT broker. Now, I have read the begginers guides and cannot for the life of me find the resolution to my problem.

I’ve managed to flash my Sonoff basic with Tasmota and can subscribe to the topic ‘garageDoor’ via ssh terminal:

mosquitto_sub -h localhost -t "+/garageDoor/#" -v

and recieve the following everytime I press the Sonoff button manually:

tele/garageDoor/LWT Online
cmnd/garageDoor/POWER (null)
stat/garageDoor/RESULT {"POWER":"ON"}
stat/garageDoor/POWER ON
stat/garageDoor/RESULT {"POWER":"OFF"}

In addition i can also manually switch on and off using:

mosquitto_pub -h localhost -t "cmnd/garageDoor/POWER" -m ON
mosquitto_pub -h localhost -t "cmnd/garageDoor/POWER" -m OFF

However, no matter what I do I cannot get the button to operate this in the UI.

Please see my setup for all files:

home.items:

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

home.sitemap:

sitemap home label="Home" {

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

mqqt.cfg:

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
mqttoh.url=tcp://192.168.0.10:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
mqttoh.clientId=openhabianMQTT

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.
mqttoh.user=openhabian

# Optional. Password to authenticate with the broker.
mqttoh.pwd=openhabian

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>

The above clientID and username/password are set in the MQQT section on Tasmota.

I have noticed mqqt connection is lost in the tail:

2018-08-19 14:08:36.680 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to 'mqttoh' was lost: Connection lost : ReasonCode 32109 : Cause : null

2018-08-19 14:08:36.685 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting connection helper to periodically try restore connection to broker 'mqttoh'

2018-08-19 14:08:46.694 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'mqttoh'

2018-08-19 14:08:47.755 [ERROR] [t.mqtt.internal.MqttBrokerConnection] - MQTT connection to broker was lost

org.eclipse.paho.client.mqttv3.MqttException: Connection lost

	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:146) [226:org.openhab.io.transport.mqtt:1.12.0]

	at java.lang.Thread.run(Thread.java:748) [?:?]

Caused by: java.io.EOFException

	at java.io.DataInputStream.readByte(DataInputStream.java:267) ~[?:?]

	at org.eclipse.paho.client.mqttv3.internal.wire.MqttInputStream.readMqttWireMessage(MqttInputStream.java:65) ~[?:?]

	at org.eclipse.paho.client.mqttv3.internal.CommsReceiver.run(CommsReceiver.java:107) ~[?:?]

	... 1 more

Any help would be greatly appreciated!

Many thanks in advanced :slight_smile:

Jeevs

Try commenting out the mqttoh.clientId=openhabianMQTT in the mqtt.cfg

Then run this all on the same line : ```
sudo service openhab2 stop && sudo rm -rf /var/lib/openhab2/cache/* && sudo rm -rf /var/lib/openhab2/tmp/* && sudo reboot

You may also need to uninstall then reinstall the MQTT binding and check if the MQTT action binding is installed, if so uninstall it. You can add it back later if needed, but to test just use the MQTT binding.
1 Like

Hi, Thanks for your quick response.

Not to question your knowledge, If i do this what do i enter in the Sonoff MQTT configuration as the ClientID?

Thank you :slight_smile:

Screenshot%20at%202018-08-19%2009-00-30

Here is a pic from one of my sonoff’s, client is same as topic but with the numbers.

1 Like

That’s geat thank you! Can you see any issues with my button for the sonoff?

In your items file try changing rollershutter to light and test if it works.

1 Like

Hi,

By running those commands you sent, I can no longer get into openHAB. Trail:

2018-08-19 15:29:15.410 [WARN ] [raf.features.internal.osgi.Activator] - Error starting activator

java.io.IOException: Unexpected end of input at 1:1

at org.apache.karaf.features.internal.util.JsonReader.error(JsonReader.java:337) [10:org.apache.karaf.features.core:4.1.5]

at org.apache.karaf.features.internal.util.JsonReader.expected(JsonReader.java:331) [10:org.apache.karaf.features.core:4.1.5]

at org.apache.karaf.features.internal.util.JsonReader.readValue(JsonReader.java:93) [10:org.apache.karaf.features.core:4.1.5]

at org.apache.karaf.features.internal.util.JsonReader.parse(JsonReader.java:58) [10:org.apache.karaf.features.core:4.1.5]

at org.apache.karaf.features.internal.util.JsonReader.read(JsonReader.java:52) [10:org.apache.karaf.features.core:4.1.5]

at org.apache.karaf.features.internal.region.DigraphHelper.readDigraph(DigraphHelper.java:90) [10:org.apache.karaf.features.core:4.1.5]

at org.apache.karaf.features.internal.region.DigraphHelper.loadDigraph(DigraphHelper.java:70) [10:org.apache.karaf.features.core:4.1.5]

at org.apache.karaf.features.internal.osgi.Activator.doStart(Activator.java:131) [10:org.apache.karaf.features.core:4.1.5]

at org.apache.karaf.util.tracker.BaseActivator.run(BaseActivator.java:242) [10:org.apache.karaf.features.core:4.1.5]

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:?]

at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

at java.lang.Thread.run(Thread.java:748) [?:?]

The only change made was:

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

to

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

correct?

1 Like

The above is all I ran, after reboot cannot get into the UI. Did not manage to get as far as changing the button icon

What are you using to access the UI, the IP w/ :8080 or hostname?

1 Like

IP:8080 (192.168.0.10:8080) I can view the log viewer and fails to load anything else once that error is reached…

SSH to console and ```
sudo systemctl start openhab2.service

Or this if the above does not work:
sudo /etc/init.d/openhab2 restart
1 Like

I’m afraid not, same error. Does this mean I will need to re-install openHAB?

Go to /etc/openhab2/services and change the addons cfg via sudo nano addons.cfg

Uncomment the #package=minimal and change minimal to standard. Ctrl x then enter to save.

1 Like

Sorry to say same error :frowning: and does nothing else.

Can you check if you have a cache and tmp folder

cd /var/lib/openhab2/cache then ls to see whats inside. Same with tmp file.

1 Like

Cache folder: 1534679836365.log org.eclipse.osgi

the log file had lots of lines but one error seemed to stand out:

Caused by: java.io.FileNotFoundException: /var/lib/openhab2/cache/org.eclipse.osgi/64/0/bundleFile (No such file or directory)

tmp: bundles fileinstall–2953306064838800275 fileinstall-4709604501647551913 fileinstall-8567311348069896646 instances karaf.pid lock port

Change this back to #package=minimal (commented out as before)

then run the sudo service openhab2 stop && sudo rm -rf /var/lib/openhab2/cache/* && sudo rm -rf /var/lib/openhab2/tmp/* && sudo reboot

again. Give it a few minutes to set back up and try the UI again, you may have to refresh the page a few times depending on your browser.

1 Like

Hi, can i confirm what the root password would be? My openhabian one isnt working.

This is odd.
From /etc/openhab2/services type ls -al to see the file owner and permissions.

1 Like