[SOLVED] Trying to enable shelly-1 relay over MQTT

  • Platform information:
    • Hardware: LXC
    • OS: openhabian
    • Java Runtime Environment: which java platform is used and what version
    • openHAB version: 2.5.8
  • Issue of the topic: I am trying to enable a shelly-1 relay over MQTT. Doesn’t work, either thru rules or CLI. See logs below. I am not using input switch, and set shelly to be in detached mode.

items file:

Switch Shelly1Piscine_Online "Online [MAP(ON_OFF_out.map):%s]"
        { channel="mqtt:topic:mosquitto:Shelly1Piscine:shelly1-xxx-online" }
Switch Shelly1Piscine_Relais "Relais [MAP(ON_OFF_out.map):%s]" <switch> 
	{ channel="mqtt:topic:mosquitto:Shelly1Piscine:shelly1-xxx-relay-0" }
Switch Shelly1Piscine_Bouton "Bouton [MAP(ON_OFF_out.map):%s]" <switch> 
        { channel="mqtt:topic:mosquitto:Shelly1Piscine:shelly1-xxx-input-0" }
Switch Shelly1Piscine_BoutonLongpush "Bouton appui-long [MAP(ON_OFF_out.map):%s]" <switch>
        { channel="mqtt:topic:mosquitto:Shelly1Piscine:shelly1-xxx-input-0-longpush" }
Number Shelly1Piscine_SondesTemp1 "Sonde #1 [%s °C]" <temperature>
        { channel="mqtt:topic:mosquitto:Shelly1Piscine:shelly1-xxx-temp-0" }
Number Shelly1Piscine_SondesTemp2 "Sonde #2 [%s °C]" <temperature>
        { channel="mqtt:topic:mosquitto:Shelly1Piscine:shelly1-xxx-temp-1" }
Number Shelly1Piscine_SondesTemp3 "Sonde #3 [%s °C]" <temperature>
        { channel="mqtt:topic:mosquitto:Shelly1Piscine:shelly1-xxx-temp-2" }
Number Shelly1Piscine_Temp "Température Piscine [%.1f °C]" <temperature>
Number timerRelaisPiscine "Timer pour la pompe de piscine"

things file:

        Thing mqtt:topic:mosquitto:Shelly1Piscine "Shelly1 Piscine et Sondes Température" (mqtt:broker:mosquitto) @ "Shellies" {
                Type switch : shelly1-xxx-online "Online" [ stateTopic="shellies/shelly1-xxx/online", on="true", off="false"]
                Type switch : shelly1-xxx-relay-0 "Pompe-Piscine" [ stateTopic="shellies/shelly1-xxx/relay/0", on="on", off="off", commandTopic="shellies/shelly1-553A95/relay/0/command", on="on", off="off" ] 
		Type switch : shelly1-xxx-input-0 "Input-0" [ stateTopic="shellies/shelly1-xxx/input/0", on="1", off="0"]
		Type switch : shelly1-xxx-input-0-longpush "Input-0-longpush" [ stateTopic="shellies/shelly1-xxx/longpush/0", on="1", off="0"]
		Type number : shelly1-xxx-temp-0 "Temp-0" [ stateTopic="shellies/shelly1-xxx/ext_temperature/0"]
                Type number : shelly1-xxx-temp-1 "Temp-1" [ stateTopic="shellies/shelly1-xxx/ext_temperature/1"]
                Type number : shelly1-xxx-temp-2 "Temp-2" [ stateTopic="shellies/shelly1-xxx/ext_temperature/2"]

File ON_OFF_out.map


Here is what happens when I try to send ON command : Shelly1Piscine_Relais.sendCommand(ON)

2020-09-07 22:22:46.552 [ome.event.ItemCommandEvent] - Item ' **Shelly1Piscine_Relais** ' received command ON
2020-09-07 22:22:46.552 [nt.ItemStatePredictedEvent] - **Shelly1Piscine_Relais** predicted to become ON
2020-09-07 22:22:46.553 [vent.ItemStateChangedEvent] - **Shelly1Piscine_Relais** changed from OFF to ON
2020-09-07 22:23:11.164 [vent.ItemStateChangedEvent] - **Shelly1Piscine_Relais** changed from ON to OFF

Any clue? First time I am playing with shelly relays…

Could you reformat your post, and put the configurations in between three backticks (`)?

Like this

Edit: perfect!

1 Like

Sorry I never remember how to do this :smiley:

OK, so two immediate things:

  1. You have two on/off transforms for your relais
  2. Have you been able to send the “on” message to shellies/shelly1-553A95/relay/0/command via mosquitto_pub or a program like MQTT Explorer? It’s worth making sure that the MQTT system itself is working properly, before troubleshooting openHAB.

Ok will try tomorrow. However receiving a lot of other information on MQTT, just not sending any for now.
The 2 transforms I tried to add because one is for receiving information, the other one is for sending command. However I admit this may be wrong.
I know the relay has to received “on” for sure, and not “ON”, so this has to be transformed somewhere (and not sure how to do this).

It works in both directions. You only need one of each.

What is your device called? shelly1-553A95 or shelly-xxx?

xxx I added in this post to make it generic, but this is correct in the files. Things file updated in the post.

OK. And do any of your channels/items work? Or are they all not working?

Actually, your Thing definition looks unusual to me:

Thing mqtt:topic:mosquitto:Shelly1Piscine "Shelly1 Piscine et Sondes Température" (mqtt:broker:mosquitto) @ "Shellies" {

Do you have your bridge to Mosquitto defined separately ((mqtt:broker:mosquitto) suggests you do)? The mosquitto between topic and Shelly1Piscine is, I think, not required/not correct.

Minor detail - you can only have one parameter with the same name. So duplicate on= off= aren’t doing anything useful.
In this case of MQTT Things, the on= and off= serve for both in and out transactions.
You’re set up to listen for e.g. “on” payload incoming on your stateTopic, and for sending “on” payload on your commandTopic.

What you’ll find really useful for investigating these issues is an external tool like mqtt.fx so you can monitor the MQTT traffic.

Actually, this is probably correct. Command mqtt channel was not set properly.
Did not think about trying to send MQTT command, since first time I am doing so. thanks for the advice, I am using MQTT explorer. Will confirm tomorrow, since this is driving a pump, and rename to solved if confirmed. thanks again, sometimes my eyes can’t see stupid errors like this :smiley:

Was setting the value correctly, openhab was seeing this, however after sometime, shelly MQTT was sending real state which remained OFF since not properly driven to ON. this should also explain the toggling in the logs.

1 Like

No problem - when staring at something for so long, it becomes difficult to see what the issue is. Let us know how you get on!

Using MQTT explorer, I am seeing the MQTT command being sent to a non existing shelly on my network, this is so obvious now… :rofl:


ok, I had this command problem, plus it seems the shelly needs to be set as “toggle switch” (and not detached mode).