[SOLVED] Mqtt not working with items file

  • Platform information:
    • Hardware: Raspberry Pi 3 Model B Plus Rev 1.3
    • OS: Raspbian GNU/Linux 9 (stretch)
    • Java Runtime Environment: openjdk version “1.8.0_152”
      OpenJDK Runtime Environment (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
      OpenJDK Client VM (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 25.152-b76, mixed mode, Evaluation)
    • openHAB version: openHAB 2.4.0~20181018164807-1 (Build #1399)
  • Issue of the topic:
    I am trying to control Sonoff tasmota basic switch by openhab.
    When I use following command I am able to toggle same goes for on off commands
mosquitto_pub -h 192.168.1.3  -t "cmnd/sonoff_tubelight/power" -m "toggle"

but it is not working for configured items and sitemaps.

  • Items configuration related to the issue
Switch sonoff_tubelight "Hall Light" <light> (LR,gLight) { mqtt=">[broker:cmnd/sonoff_tubelight/power:command:*:default],<[broker:stat/sonoff_tubelight/power:state:default]" }

  • Sitemap configuration related to the issue
sitemap home label="Auto"
{

       Frame label="Hall light"
       {
               Switch item=sonoff_tubelight
       }

}


}

  • Services configuration related to the issue
    Tasmota configuration
  • logs
    When I toggle via GUI I can below logs but nothing in [mosquitto_sub -h 192.168.1.3 -v -t “#”]
2018-10-24 00:36:23.444 [ome.event.ItemCommandEvent] - Item 'sonoff_tubelight' received command OFF

2018-10-24 00:36:23.476 [vent.ItemStateChangedEvent] - sonoff_tubelight changed from ON to OFF

2018-10-24 00:36:24.656 [ome.event.ItemCommandEvent] - Item 'sonoff_tubelight' received command ON

2018-10-24 00:36:24.679 [vent.ItemStateChangedEvent] - sonoff_tubelight changed from OFF to ON

2018-10-24 00:36:25.689 [ome.event.ItemCommandEvent] - Item 'sonoff_tubelight' received command OFF

2018-10-24 00:36:25.700 [vent.ItemStateChangedEvent] - sonoff_tubelight changed from ON to OFF

2018-10-24 00:36:26.260 [ome.event.ItemCommandEvent] - Item 'sonoff_tubelight' received command ON

2018-10-24 00:36:26.269 [vent.ItemStateChangedEvent] - sonoff_tubelight changed from OFF to ON

When I toggle via " mosquitto_pub -h 192.168.1.3 -t “cmnd/sonoff_tubelight/power” -m “toggle” but nothing in logs

cmnd/sonoff_tubelight/power toggle
stat/sonoff_tubelight/RESULT {"POWER":"OFF"}
stat/sonoff_tubelight/POWER OFF

Mosquitto Version

mosquitto --help
mosquitto version 1.4.10 (build date Fri, 22 Dec 2017 08:19:25 +0000)

mosquitto is an MQTT v3.1 broker.

cat /var/lib/openhab2/config/org/openhab/mqtt.config

broker.url="tcp://192.168.1.3:1883"
service.pid="org.openhab.mqtt"

cat /etc/openhab2/services/mqtt.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
broker.url=tcp://192.168.1.3:1883

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

# 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.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

# 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>

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#<broker>.retain=<retain>

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#<broker>.async=<async>

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

I am unable to find why it is happening. Please tell me if any more logs required to identify this issue.

post your mqtt.cfg

2 Likes

I was reading this and getting to the same conclusion…

1 Like

Have you tried changing the word power to POWER in your items file?

Because you are on OH 2.4: Please make sure you have installed MQTT1. Because the default will be MQTT2, and that works completely different.

Cheers, David

2 Likes

I have posted Mqtt.cfg file also tried changing power to POWER and my mosquitto version is 1.4.10.
Still no result.
I hope I have not run into some compatibility issue.

mqtt.cfg looks good…
does your openhab.log have 2 entries upon startup of this kind:

2018-10-23 11:40:27.854 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-10-23 11:40:27.855 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'broker'

check also in the OH2 console (openhab-cli console)

openhab> bundle:list -s |grep mqtt
234 x Active   x  80 x 1.13.0.201810160911    x org.openhab.binding.mqtt
241 x Active   x  80 x 1.13.0.201810160911    x org.openhab.io.transport.mqtt

(my versions are from OH2.4 S#1400)

1 Like

Issue resolved after uninstalling mqtt binding v2 and installing v1.
Thank you Dim and David for your help. :slight_smile:

1 Like