[SOLVED] Using a push button / mqtt on a tasmota sonoff basic to control other devices

Hello guys,

An openhab2 newbie here, this is my first post, I am also new to the whole smart home scene. Ok here goes:

What I have:

  • Openhabian2 on a RPI3
  • Mosquitto MQTT2 broker
  • Several sonoff basic with tasmota firmware
  • 8 spot lights in my ceiling, each 4 are grouped and connected to one sonoff.
  • 2 window blinds each connected to one sonoff.

What I am trying to achieve:
I would like to use one push button to control lights (2 sets progressively) and the window blinds.

When I push the button (single push) the first set of lights should turn on (4 lights), when I push it again the second set should turn on (8 lights), when I push again all lights should turn off.

When I long press the button, the window blinds should open, when I long push it again the blinds should close.

What I achieved so far:
So far I got the button connected to one of the sonoffs GPIOs, and I made the necessary configuration on tasmota modules so that:

  • When I push the button, the sonoff is publishing a “TOGGLE” command to the /tasmota/cmnd/remote/POWER1
    -When I long push the button, the sonoff is publishing a “HOLD” command to the /tasmota/cmnd/remote/POWER1

I can see the published commands using MQTTLens.

Now I want to use those commands published by the sonoff to trigger a rule in which I can send proper commands to the other sonoffs to do the things I want them to do.
I spent the last couple days reading and trying everything but I couldn’t manage to get it to work, mostly due to the fact that most of the articles were using MQTT1 which has different syntax and binding configuration than MQTT2.

Below is my .things file:

mqtt:broker:mosquitto “mosquitto” [ host=“192.168.43.183”, port=“1883”, secure=false, username=“xxx”, password=“xxx”, clientID=“MOSQUITTOBROKER” ]

Thing mqtt:topic:mosquitto:Sonoff01 “Sonoff01 switch” (mqtt:broker:mosquitto) @ “Home” {
Channels:
Type switch : sonoff01sw “sonoff01 switch” [ stateTopic=“tasmota/stat/sonoff01/POWER”, commandTopic=“tasmota/cmnd/sonoff01/POWER” ]
Type string : lighttoggle01 “lighttoggle01” [ commandTopic=“tasmota/cmnd/remote/POWER1” ]

}

My .items file:

String lightchange “Light change” { channel=“mqtt:topic:mosquitto:Sonoff01:lighttoggle01” }

My .rules file:

rule “light change”
when
Item lightchange received command TOGGLE
then
logInfo(receivedCommand.toString)
end

So far I couldn’t manage to trigger the rule or see anything in the logs, if some one can provide any help or pointers I would be so grateful.

You might need to put the TOGGLE in quotes in the Rule.

You also probably need to configure your Channels to process the messages as commands. I don’t use .things files so I don’t know how to do that. In PaperUI there is a toggle in the Channel config dialog.

You can try with a received update trigger for now, though I’m not sure the binding updates the item if the new state is the same.

Watch events.log . If the Item is getting some commands or changing States you will see it there.

Thank you very much Rich,

through trial and error I finally managed to catch the “Toggle” and “HOLD” command and trigger rules based on them.