One Button - 20%, 40%, 60%, 80%, 100% - OFF steps (Amazon Dash Button)

i treid your code with a coco (433mhz) remote and rfxcom, but didn’t quite got it to work

Item Sw3 changed 
    then
    logInfo("knop_ab1_03", "keuken gewijzigd naar "+Sw3.state)
    // Assume current dim is 0 if Item is NULL, light will turn on at 20%
    val actu = if(Kitchen_c.state == NULL) 0 else Kitchen_c.state as Number

    
    val newDim =  actu + 20// calculate the new dim value
    val newState = if(newDim <= 100) ON else OFF // determine if the light should be ON or OFF

    if(newState == OFF) {
    Kitchen_h.sendCommand(OFF) }
    else {
    Kitchen_h.sendCommand(newDim)
    Sw3.postUpdate(OFF)
    }
end >

it works only the first press because then it receives an on command, but the switch stays on and the rule won’t trigger again.
so I tried to post an update but the light stays off

1 Like

Hi all, it takes a long time, but now it works :slight_smile:

2020-02-15T23:00:00Z

rule "AqaraWirelessSwitch2Go"
when
    Channel "deconz:switch:homeserver:00158d0001e83c05010006:buttonevent" triggered
then
    logInfo("AqaraWirelessSwitch2Go", "AqaraWirelessSwitch2Go wurde gedrückt")
    // Assume current dim is 0 if Item is NULL, light will turn on at 20%
    val curr = if(Licht_Buero_Deckenfluter.state === NULL) 0 else Licht_Buero_Deckenfluter.state as Number

    val newDim = curr + 20 // calculate the new dim value
    val newState = if(newDim <= 100) ON else OFF // determine if the light should be ON or OFF

    if(newState == OFF) Licht_Buero_Deckenfluter.sendCommand(OFF)
    else Licht_Buero_Deckenfluter.sendCommand(newDim)
end