MQTT publish failed

(John) #1

I am using OH2.4 with MQTTv2

I have a script (discussed in a previous topic) that switches a siren on/off until manually stopped. I have been working on this for a while now and it all seems to be fine however every once and a while OH fails with MQTT publish to /topic failed!

I have to restart OH service and it’s all good. I initially put this down to me changing settings but I’ve been no-where near OH today, went to start the siren, it worked once then failed.

Any advice or am I going to have to think of a different way of controlling this outside of OH.

0 Likes

(SiHui) #2

Error messages in openhab.log?

0 Likes

(John) #3

As mentioned in the first post it works fine then suddenly stops working (no additional messages in mosquitto log). Restart openhab2 service and it works fine. Hours/days can pass before it does it again but i need this to be reliable!

2019-05-14 13:52:20.792 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
2019-05-14 13:52:20.793 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
2019-05-14 13:53:09.694 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
2019-05-14 13:53:15.696 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
2019-05-14 13:53:21.698 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
2019-05-14 13:53:27.254 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
2019-05-14 13:53:27.255 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
2019-05-14 13:53:29.938 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
2019-05-14 13:53:34.942 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
2019-05-14 13:53:34.942 [WARN ] [home.binding.mqtt.action.MQTTActions] - MQTT publish to gs/sirens/ghsirenmtr failed!
0 Likes

(SiHui) #4

Then it may be a little harder to debug, especially when using any scripts you mentioned (I guess to build the mqtt action which was missing in 2.4 stable).
I would subscribe to the SYS topic and check the load to find out what is happening, for example with an mqtt client:

grafik

0 Likes

(John) #5

I think I may be running into this bug

But have no idea on how to workaround it

0 Likes

(SiHui) #6

Good catch, sounds like your problem and unfortunately no solution yet … :joy:

0 Likes

(John) #7

That’s a pity, I’m going to have to move my logic outside of openhab

Do you happen to know of a way or another program that can listen to a topic then run a script automatically?

0 Likes

(David Graeff) #8

I think this is fixed in recent OH versions. The report was also for OH 2.4 only. Please remember that we added MQTT Thing actions about 5 days before the release, there are plenty of bugs in that old code.

0 Likes

(John) #9

Thanks David

I’m running 2.4 stable and 1.13 of the mqtt action. Is there a recommended version of OH or the action that I should upgrade to, to try and clear this up (I really don’t want to move my logic elsewhere as when this is working it’s working very well!)

However I have just noticed that for 1.13 it says i need mqtt binding 1.x installed. i am running 2.4. coudl this be an issue?

0 Likes

(Rossko57) #10

Why do you need to use the action? Why not have a switch Item defined in the conventional way, with an MQTT channel, and send it commands?

0 Likes

(John) #11

I am running the ON/OFF rule that you kindly helped me with last week but this is initially triggered (via a separate mqtt command) from a PHP page. What we want to do is not possible from a sitemap or switch item.

0 Likes

(Rossko57) #12

??

Instead of

val mqttActions=getActions("mqtt","mqtt:broker:MQTTBroker")
      mqttActions.publishMQTT("siren","0")

which gives you grief, you -
set up the MQTT binding to subscribe to your broker
make a thing for your siren topic
add a switch channel with commandTopic
specify on/off to 0/1

Then add an Item to use that channel

Switch mySirenItem "siren switch" { channel="mqtt:topic:mysirenthing:controlchannel"}

Then you just send it a command from your rule

mySirenItem.sendCommand(ON)`

Also useful

2 Likes

(John) #13

That works a treat. MQTT Action now uninstalled

Thank you!

1 Like

(Alex Spitz) #14

Hi! I’m having some trouble here … Maybe you can help me …

MQTT.things

  Thing topic Cortina_Test "Cortina en Cuenca" @ "Cortinas" {
   Channels:
     Type switch : power "Power" [ stateTopic="stat/Cortina/POWER1", commandTopic="cmnd/Cortina/POWER1" ]
  }

Sonoff.items

Rollershutter Cortina_Test     "Cortina"
Switch Cortina_Test_Up "Cortina Up" { channel="mqtt:topic:mqtt_broker:Cortina:power" }

Rules.rules

rule "G_sonoff"
when
    Item Cortina_Test received command
then
    Cortina_Test_Up.sendCommand(ON)
end

The log shows:
16:20:24.605 [INFO ] [smarthome.event.ItemCommandEvent ] - Item 'Cortina_Test_Up' received command ON

But nothing else happens … what am I missing?
I’m trying to control a Sonoff Dual thru a rollershutter item but since neither publishMQTT works nor the rollershutter on 2.4 I’m looking at other options.

Thanks for taking the time.

0 Likes

(Rossko57) #15

The rule is listening for commands to Cortina_Test, not Cortina_Test_Up
I do not expect the rule to do anything here.

The Cortina_Test_Up Item is bound to a channel mqtt:topic:mqtt_broker:Cortina:power
I cannot tell if you have a broker called mqtt_broker or not.
You do not seem to have a Thing called Cortina, although you do have a Thing called Cortina_Test
I do not expect the binding to do anything here.

0 Likes

(Alex Spitz) #16

Let me add some more info and my config files …

What I’m trying to achieve is to be able to control a rollershutter from the basic UI, with a sitemap with the rollershutter switch so I get the up, stop and down buttons.

So on my mind, I have a switch Cortina_Test, that triggers a rule with a select case depending on which button was pressed and acts accordingly, with a sendCommand(ON) to the POWER1 or POWER2 from my Sonoff Dual R2 flashed with Tasmota.

If you thinks there’s a better way to achieve the same result, I’m all ears.

So, back to my files …

ITEMS

Group:Switch:OR(ON, OFF) gCortinas "Todas las Cortinas"

//Blinds Controls
Switch Cortina_Test_Up "Cortina Up" { channel="mqtt:topic:mqtt_broker:Cortina_Test_Up:power" }
Switch Cortina_Test_Down "Cortina Down" { channel="mqtt:topic:mqtt_broker:Cortina_Test_Down:power" }
Rollershutter Cortina_Test     "Cortina"     (gCortinas) { channel="mqtt:topic:mqtt_broker:Cortina_Test:power" }

THINGS

Bridge mqtt:broker:mqtt_broker "MQTT Broker Alex" [ host="127.0.0.1", secure=false, clientID="MQTT_Cuenca"]
{
  Thing topic Cortina_Test_Up "Cortina en Cuenca" @ "Cortinas" {
   Channels:
     Type switch : power "Power" [ stateTopic="stat/Cortina/POWER1", commandTopic="cmnd/Cortina/POWER1" ]
  }
 
  Thing topic Cortina_Test_Down "Cortina en Cuenca" @ "Cortinas" {
   Channels:
     Type switch : power "Power" [ stateTopic="stat/Cortina/POWER2", commandTopic="cmnd/Cortina/POWER2" ]
  }

  Thing topic Cortina_Test "Cortina en Cuenca" @ "Cortinas" {
   Channels:
     Type switch : power "Power" [ stateTopic="stat/Cortina/POWER", commandTopic="cmnd/Cortina/POWER" ]
  }

}

SITEMAP

sitemap casa label="Casa Banana" {
    Frame label="Cortinas" icon="groundfloor" {
        Switch item=Cortina_Test label="Cortina Test []"
    }

	Frame label="Master Shutters Control" {
			Switch item=gCortinas icon="blinds" mappings=[ON="Subir Todo"]
			Switch item=gCortinas icon="blinds" mappings=[OFF="Bajar Todo"]      
    }

}

RULES

rule "Move Rollershutter"
when
    Item Cortina_Test received command
then
    switch (receivedCommand) {
        case UP: Cortina_Test_Up.sendCommand(ON)
        case DOWN:Cortina_Test_Down.sendCommand(ON)
        case STOP: {
            if(Cortina_Test_Up.state == ON) Cortina_Test_Up.sendCommand(OFF)
            if(Cortina_Test_Down.state == ON) Cortina_Test_Down.sendCommand(OFF)
        }
    }
end

That’s all I have … Any thoughts? Thanks again !!!

0 Likes

(Alex Spitz) #17

Apparently, it’s working! Weird …

Is there a better way to achieve the same result? Any tips?

Thanks for the help!

0 Likes