OH2 MQTT Mosquitto read only

  • Platform information:

    • Hardware: Synology DS213+ 512MB
    • OS: DSM 6.2.3-25426 Update 2
    • Java Runtime Environment: 1.8.0_6-0041
    • openHAB version: 2.5.2.00
  • Issue of the topic:

I’ve been struggling for a long time to get MQTT working in openHAB2. I have Mosquitto running on the Synology (as well as OH2, hence localhost in MQTT broker thing). Using MQTT.fx I am able to see status from Sonoff Tasmota devices (and others) and issue commands that work. In OH2 BasicUI or PaperUI I can see device status but not issue commands.

Originally in 2.4 I set everything up in PaperUI. I then did a clean install of 2.5 and have configured things and items in files. I have the MQTT Binding installed.

Lets take a Sonoff Basic R3 as an example. Here is what I see in my BasicUI site map:


I can’t switch it on and off from here, but if I paste the command topic from my channel def into MQTT.fx, the Sonoff switches, and the Sonoff MQTT Result field in the site map above updates to show the new state.

Here is the broker def:

Bridge mqtt:broker:mosquitto "Mosquitto MQTT broker" [
    host="127.0.0.1",
    secure=false,
    port=1883,
    qos=0,
    retain=false,
    keep_alive_time=30000,
    reconnect_time=60000,
    username="myusername",
    password="mypassword"
    ]

and the Sonoff thing:

Thing mqtt:topic:snf_R3 "Sonoff R3" (mqtt:broker:mosquitto) {
    Channels:
    Type switch : power "Power" [ statetopic="stat/sonoff_r3/POWER", commandtopic="cmnd/sonoff_r3/POWER", on="ON", off="OFF" ]
    Type string : reachable "Reachable" [ stateTopic="tele/sonoff_r3/LWT" ]
    Type number : rssi "WiFi Signal Strength" [ stateTopic="tele/sonoff_r3/STATE", transformationPattern="JSONPATH:$.Wifi.RSSI"]
    Type string : version "Firmware Version" [stateTopic="stat/sonoff_r3/STATUS2", transformationPattern="JSONPATH:$.StatusFWR.Version"]
    Type string : result "Result" [stateTopic="stat/sonoff_r3/RESULT"] 
}

and the Sonoff item:

Switch Sonoff_R3_1_Power "Power" <light> (gSonoff) {channel="mqtt:topic:snf_R3:power"}
String Sonoff_R3_1_Reachable "Reachable" (gSonoff) {channel="mqtt:topic:snf_R3:reachable"}
Number Sonoff_R3_1_RSSI "RSSI [%d %%]" (gSonoff) {channel="mqtt:topic:snf_R3:rssi"}
String Sonoff_R3_1_Firmware "Firmware [%s]" (gSonoff) {channel="mqtt:topic:snf_R3:version"}
String Sonoff_R3_1_Info1 "Sonoff: MQTT Info1 [%s]" (gSonoff) {channel="mqtt:topic:snf_R3:info1"}
String Sonoff_R3_1_Status2 "Sonoff: MQTT Status2 [%s]" (gSonoff) {channel="mqtt:topic:snf_R3:status2"}
String Sonoff_R3_1_Result "Sonoff: MQTT Result [%s]" (gSonoff) {channel="mqtt:topic:snf_R3:result"}

and the sitemap:

    Frame label="Lights" {
        Text item=Sonoff_R3_1_Reachable
        Switch item=Sonoff_R3_1_Power label="Up light"
        Text item=Sonoff_R3_1_RSSI
        Text item=Sonoff_R3_1_Firmware
        Text item=Sonoff_R3_1_Info1
        Text item=Sonoff_R3_1_Status2
        Text item=Sonoff_R3_1_Result         
    }

I’m not a great expert at logging, but what I can see in openhab.log is:
2020-10-21 18:54:44.724 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to ‘127.0.0.1’ with clientid e5bb760e-a6fe-4fc2-9d10-a33bf596c981

and events.log:
2020-10-21 19:49:25.670 [vent.ItemStateChangedEvent] - Sonoff_R3_1_RSSI changed from 66 to 70

and when I issue a power command in MQTT.fx, events.log shows:
2020-10-21 19:55:24.321 [vent.ItemStateChangedEvent] - Sonoff_R3_1_Result changed from {“POWER”:“OFF”} to {“POWER”:“ON”}

Any ideas why I can only read device status and not command anything?

There are a ton of MQTT posts that I’ve carefully read and tried many adjustments (e.g. 3 restarts of OH, cache clear, one thing per thing file), but nothing seems to make a difference. Apologies if I missed an answer already given.

Many thanks!

The correct syntax in such a file is mandatory, your words commandtopic and statetopic ardmissing the uppercase character T.

4 Likes

Thanks @opus , that worked after a restart.