Mqtt publishing issue

Hi,

I’m trying to use a switch item in openhab2 to publish to mqtt.
If i manually publish stat/sonoff/POWER openhab displays the correct switch state.
General publishing of changes appears to be working with the eventbus binding.
I cannot get openhab to publish any state changes for my switch.

This is my item:

Switch testswitch_mqtt "testswitch_mqtt" <light> {mqtt="<[mosquitto:stat/sonoff/POWER:state:default],>[mosquitto:cmnd/sonoff/power:command:ON:1],>[mosquitto:cmnd/sonoff/power:command:OFF:0]" }

This is my sitemap:

sitemap kitchen label="kitchen" {
    Switch item=testswitch_mqtt
}

I’m struggling to come up with an explanation for this. I’ve tried breaking up the switch into multiple switches and replacing 1 and 0 with default.

Thanks!

You have OFF also publish a 1 like ON

Hmm i just typed that out wrong here.
my actual config is this:

mqtt="<[mosquitto:stat/sonoff/POWER:state:default],>[mosquitto:cmnd/sonoff/power:command:ON:1],>[mosquitto:cmnd/sonoff/power:command:OFF:0]"

Switch Dimmer60 “Dimmer 60%”{mqtt=">[mymosquitto:mymosquitto/ParticlePi/DimmerOn:command:on:60],>[mymosquitto:mymosquitto/ParticlePi/DimmerOn:command:off:5]"}

This one works using the command format…the “mymosquitto/ParticlePi/DimmerOn” is my MQTT address …The command I think is the state of the switch position…and the number is what my device sees as the subject posted …it actually works …you can subscribe to the subject using " mqtt tool " app and toggle the buttons to see if it’s posting if it posts and you see it but nothing happens you need to check on your Arduino or whatever your using to make sure your setup for s right

You don’t need the first string of mqtt …it’s confusing OpenHAB as to what to do …use the format I have and it’ll work flawlessly

If you want an external status sent to OpenHAB …make a new line and have Mqtt send the info … using the mqtt in but you’ll need a new line in your sitemap as a number item …

Like
(Sitemap)
Number item switch_status

(Items)

Number switch_status “Kitchen Switch [%.2f]” {mqtt="<[mosquitto:stat/sonoff/Power:state:default]"}

I’ve tried to replicate your example and used this configuration:
item:

Switch Dimmer60 "Dimmer 60%"{mqtt=">[mosquitto:mymosquitto/ParticlePi/DimmerOn:command:on:60],>[mosquitto:mymosquitto/ParticlePi/DimmerOn:command:off:5]"}

sitemap:

    Switch item=Dimmer60

In mqtt.fx(#) there is no activity if i switch the switch on and off.
I get this log output:

2017-03-02 18:22:48.511 [DEBUG] [binding.mqtt.internal.MqttItemConfig] - Loaded MQTT config for item 'Dimmer60' : 0 subscribers, 2 publishers

So the mqtt configuration seems to be at least syntactically correct.
Even my old configuration appears to be alright as it reports 1 subscriber and 2 publishers.

  • Why does your MQTT topic begin with mymosquitto? Please share your mqtt.cfg file (redacting sensitive parts) to validate the item.
  • The commands in the binding config strings must be ON and OFF, not on and off.

I’ve copied @jade7272 example and only changed the broker part to see if there was something wrong with my syntax.
My mqtt.cfg file is working already as the eventbus is able to publish through it.

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

I was using mosquitto for something else and was having compatibility issues so I just put in mymosquito …it could be anything I’m thinking …as long as your consistent …I am on my iPad and it’s hard to copy the config files through the app I’m using …You are right about the on and off for some reason it worked anyway …strange …I’ll try in a sec

The commands won’t be sent from the Switch item unless the binding config strings use the proper uppercase commands; let us know if that helps!

############################################################################################Transport configurations############################################################################################################################# MQTT Transport ######################################## Define your MQTT broker connections here for use in the MQTT Binding or MQTT# Persistence bundles. Replace with a id you choose.## URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883mqtt:mymosquitto.url=tcp://localhost:1883# Optional. Client id (max 23 chars) to use when connecting to the broker.# If not provided a default one is generated.#mqtt:.clientId=

Don’t have much in the config file just the mqtt host

I’ve also tried uppercase ON and OFF there is nothing being sent out. Is there some way i can debug by turning on additional logging?

You know when I have my start_debug.sh going it doesn’t seem to go out either but then my leds do what they are supposed to do …do you have a mqtt tool you can subscribe to ? That’s how I found out the mistakes I made when posting to the server …you can also use node red as a test bed subscribing to the mqtt stream and tweeting the information it receives

Hey maybe paste your new config and I’ll have a look

1 Like

I’ve found whats causing my issue:
I’ve been testing my sitemap using habmin exclusively. Today I tried to just use a plain button without anything hooked up and it didn’t cause any events on click.