- openHABian v3 on rPi4
I have a Sonoff button that sends three actions: single
, double
, and long
, which I’d like to translate to commands.
These actions should behave like toggles. E.g., single
= ON|OFF
.
My rule looks as follows:
val String LOG_PREFIX = "ShedLights."
var int sonoff_button_02_switch = 0
rule "ShedLights: translate button actions to commands"
when
Channel "mqtt:topic:mosquitto:sonoff_button_02:buttonaction" triggered
then
//if (debug == 1)
{
logInfo(LOG_PREFIX + "03.01",
"SO Button 02 buttonaction is {}", receivedEvent)
}
switch(receivedEvent)
{
case "single":
{
if (sonoff_button_02_switch == 0)
{
SonOFF_Button_02_Switch.sendCommand(ON)
sonoff_button_02_switch = 1
}
else
{
SonOFF_Button_02_Switch.sendCommand(OFF)
sonoff_button_02_switch = 0
}
}
}
//if (debug == 1)
{
logInfo(LOG_PREFIX + "03.02",
"SO Button 02 state is {}", sonoff_button_02_switch)
}
end
… but it does not get triggered.
I have a thing, with a channel called buttonaction as string, receiving this topic:
zigbee2mqtt/KDL/Max_Troffer_Light/action
- id: buttonaction
channelTypeUID: mqtt:string
label: Button Action
description: ""
configuration:
stateTopic: zigbee2mqtt/KDL/Max_Troffer_Light/action
Questions:
- Is this even the right approach?
- If so, why is the rule not triggered?
- If not, any pointers for a better approach are appreciated.