[SOLVED] MQTT Switch doesn't work

I am trying to make a simple switch that would send message to the MQTT topic

here is my .items:

String DE1State {mqtt="<[mosquitto:de1/state_update:state:default]"}  

Switch DE1 "DE1" ["Switchable"] {mqtt=">[mosquitto:de1/command:command:*:Switch ${itemName} was turned ${command}]"}

My .sitemap:

sitemap demo label="My MQTT Demo Switches" {
        Frame label="Demo" {
                Text item=DE1State
                Switch item=DE1
        }

}

I see that my string idem gets updated when I publish something to de1/state_update topic, but nothing happened when I toggle switch in Habmin - I don’t see any topic gets published…

I tried
Switch DE1 "DE1" ["Switchable"] {mqtt=">[mosquitto:de1/command:command:*:default"}

it didn’t work either…

Any ideas what I am doing wrong?

You need a space after the { and before the }

Switch DE1 "DE1" ["Switchable"] { mqtt=">[mosquitto:de1/command:command:*:Switch ${itemName} was turned ${command}]" }

Hm… I don’t have space in my String my item…

Yours:

Switch DE1 "DE1" ["Switchable"] {mqtt=">[mosquitto:de1/command:command:*:Switch ${itemName} was turned ${command}]"}

Mine:

Switch DE1 "DE1" ["Switchable"] { mqtt=">[mosquitto:de1/command:command:*:Switch ${itemName} was turned ${command}]" }

See the difference now?

Also, looking at openhab.log it didn’t fail parsing and actually added subscription on topic de1/command:

2018-06-10 13:02:14.878 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item ‘DE1’ : 1 subscribers, 1 publishers
2018-06-10 13:02:14.878 [DEBUG] [t.mqtt.internal.MqttBrokerConnection] - Starting message consumer for broker ‘mosquitto’ on topic ‘de1/command’

Adding space didn’t help

You should have 1 publisher, 0 subscribers
It that the entire item definition?

Try this:

Switch DE1 "DE1" ["Switchable"] { mqtt=">[mosquitto:de1/command:command:*:default]" }

ONLY

Didn’t help…

Square bracket missing at the end.

@hmerk, Yes I missed that
But the longer definition should work, though. Going back to basics.

Switch DE1 "DE1" ["Switchable"] { mqtt=">[mosquitto:de1/command:command:*:default]" }

still doesn’t work :frowning:

Mqtt.cfg file please

mosquitto.url=tcp://localhost:1883
mosquitto.clientId=openhab
mosquitto.retain=true
mosquitto.async=false

could be a typo, but try to use the correct quote marks everywhere: "" instead of “”

Also, add a spaces in the tag (it should work also without i think)

Switch DE1 "DE1" [ "Switchable" ] { mqtt=">[mosquitto:de1/command:command:*:default]" }

you should have some log entry about errors in your items file.

I didn’t see these bloody quotes on my phone screen!

1 Like
mosquitto.url=tcp://127.0.0.1:1883
mosquitto.clientId=openhab
mosquitto.retain=true
mosquitto.async=false

Show me the openhab.log when OH starts and when you edit the item file, please
Also can you publish the complete items file, thanks

1 Like

Complete .items file:

String DE1State { mqtt="<[mosquitto:de1/state_update:state:default]" }

//Switch DE1 "DE1" ["Switchable"] {mqtt="<[mosquitto:de1/state_update:state:default],>[mosquitto:de1/turn_on:command:ON:1],>[mosquitto:de1/turn_off:command:OFF:0]"}
//Switch DE1 "DE1" ["Switchable"] { mqtt=">[mosquitto:de1/command:command:*:default],<[mosquitto:de1/command:command:*:default]" }
//Switch DE1 "DE1" ["Switchable"] {mqtt=">[mosquitto:de1/command:*:Switch ${itemName} was turned ${command}]"}

//Switch DE1 "DE1" ["Switchable"] { mqtt=">[mosquitto:de1/command:command:*:default" }

Switch DE1 "DE1" ["Switchable"] { mqtt=">[mosquitto:de1/command:command:*:default]" }

openhab.log:

2018-06-11 16:33:22.745 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item ‘DE1’ : 0 subscribers, 1 publishers
2018-06-11 16:33:22.748 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘DE1Plus.items’
2018-06-11 16:33:22.750 [DEBUG] [.internal.MqttGenericBindingProvider] - Removing message consumers for item DE1State
2018-06-11 16:33:22.750 [DEBUG] [t.mqtt.internal.MqttBrokerConnection] - Unsubscribing message consumer for topic ‘de1/state_update’ from broker ‘mosquitto’
2018-06-11 16:33:22.750 [DEBUG] [.internal.MqttGenericBindingProvider] - Removing message publishers for item DE1State
2018-06-11 16:33:22.751 [DEBUG] [.internal.MqttGenericBindingProvider] - Removing message consumers for item DE1
2018-06-11 16:33:22.751 [DEBUG] [.internal.MqttGenericBindingProvider] - Removing message publishers for item DE1
2018-06-11 16:33:22.751 [DEBUG] [t.mqtt.internal.MqttBrokerConnection] - Removing message producer for broker ‘mosquitto’
2018-06-11 16:33:22.751 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item ‘DE1State’ : 1 subscribers, 0 publishers
2018-06-11 16:33:22.752 [DEBUG] [t.mqtt.internal.MqttBrokerConnection] - Starting message consumer for broker ‘mosquitto’ on topic ‘de1/state_update’
2018-06-11 16:33:22.752 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item ‘DE1’ : 0 subscribers, 1 publishers
2018-06-11 16:33:22.757 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘DE1Plus.items’
2018-06-11 16:33:22.759 [DEBUG] [.internal.MqttGenericBindingProvider] - Removing message consumers for item DE1State
2018-06-11 16:33:22.759 [DEBUG] [t.mqtt.internal.MqttBrokerConnection] - Unsubscribing message consumer for topic ‘de1/state_update’ from broker ‘mosquitto’
2018-06-11 16:33:22.760 [DEBUG] [.internal.MqttGenericBindingProvider] - Removing message publishers for item DE1State
2018-06-11 16:33:22.760 [DEBUG] [.internal.MqttGenericBindingProvider] - Removing message consumers for item DE1
2018-06-11 16:33:22.760 [DEBUG] [.internal.MqttGenericBindingProvider] - Removing message publishers for item DE1
2018-06-11 16:33:22.761 [DEBUG] [t.mqtt.internal.MqttBrokerConnection] - Removing message producer for broker ‘mosquitto’
2018-06-11 16:33:22.761 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item ‘DE1State’ : 1 subscribers, 0 publishers
2018-06-11 16:33:22.761 [DEBUG] [t.mqtt.internal.MqttBrokerConnection] - Starting message consumer for broker ‘mosquitto’ on topic ‘de1/state_update’
2018-06-11 16:33:22.762 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item ‘DE1’ : 0 subscribers, 1 publishers

It should work
Do you have an MQTT monitor like mqtt.fx or mqtt-spy?
Get one and subcribe to the topic de1/command. You should see the payload ON and OFF when you action the switch.

It doesn’t work, I use mosquito_sub -t de1/command to listen and when trigger control from habmin’s sitemap I don’t see anything in terminal where mosquito_sub is runnin