Alarm switch: How combine physical switch and "software" switch? rule

Then all you need is this.

rule "Alarm"
when
    Item GPIO_BUTTON changed
then
    if (GPIO_LAMP.state == ON) {
        GPIO_LAMP.sendCommand(OFF)
    }
    else {GPIO_LAMP.sendCommand(ON)
    }
end

:frowning:

Now:
When LED is “ON”, so long as pressing the goes “off”, than “ON” again
When LED is “off”, so long as pressing the LED goes “ON”, than “Off” again
(no flicker)

The physical switch on the GPIO (push button) should proceed as a “switch”:
First press: Alarm is activated
Next press: Alarm is deactivated
Next press: Alarm is activated again …

Maybe this was not explained clearyl from side, sorry.

I Forgot to change the trigger.:roll_eyes:

rule "Alarm"
when
    Item GPIO_BUTTON changed to ON
then
    if (GPIO_LAMP.state == ON) {
        GPIO_LAMP.sendCommand(OFF)
    }
    else {GPIO_LAMP.sendCommand(ON)
    }
end

With using changed only, and a button, then each press and release causes the rule to run.

Hmmm,
now nothing happens when pressing the physical button … in log the event is shown, so GPIO is fine wired …
When pressing the soft-switch in oH the LED go on (or off).

(and I try to understand the syntax and for me it make sense / looks correct for me)

If your not using MAP transformation to convet the normal OPEN/CLOSED of a contact item then change the rule to use CLOSED instead of ON like below.

rule "Alarm"
when
    Item GPIO_BUTTON changed to CLOSED
then
    if (GPIO_LAMP.state == ON) {
        GPIO_LAMP.sendCommand(OFF)
    }
    else {GPIO_LAMP.sendCommand(ON)
    }
end

EDIT: I mentioned using OPEN but then realized that is the normal state so best to use CLOSED.

1 Like

:+1: :+1:

Thanks a lot, I think now I have a good starting point to modify to my requirements (activation delay, …)

(So if I need help, I will write here again :wink: )

@Topsurfer Glad it’s working.:+1:

It may be best to start another topic as this one is solved. This will help others when searching the forum looking for a particular solution.

If you would please click the square box on the post that provided the solution and edit the title to start with [Solved]. This will help others with a similar issue find a quick solution.

Thanks