Hi,
as written, actuall I only have a physical (hardware) switch to activate or deactivate the alarm system.
Now I wish to be able to switch the alarm system on and off with an additionally “software” switch.
They are different “switches”, because the existing one is real, the new one is a software switch in openHAB only.
Both will do the same at the end: Activate or deactivate the alarm-system (independently).
But where is “connection” between the switch on GPIO24 and the LED on GPIO23 which says:
If GPIO_Button was pressed, switch on the GPIO_LAMP?
I expect and thought there must be a rule ? I overlook something?
Not sure what you’re saying? The GPIO Items are unconnected as they stand, and a rule would be needed to make things happen in response to button pressing. There is no example rule in the linked posting, but it would be straightforward.
For your alarm project, you could rename the LED Item as “Alarm Active” and use it in your rules and sitemap directly. That is your “soft switch” could be the LED Item.
For the button, you could have a rule triggered from changed to CLOSED that changed the state of “alarm active”
rule "Alarm setting toggle"
when Item myPushbutton changed to CLOSED
then
if( Alarmswitch.state == ON )
{
Alarmswitch.sendCommand(OFF)
} else {
Alarmswitch.sendCommand(ON)
}
end
Later on, you could add cleverness that stopped the alarm being set if a door was open etc.
In my example I show, these two lines (switch GPIO_Lamp …, contact GPIO_Button …), are they “enough” to switch a LED (on GPIO 23) with a physical switch (on GPIO 24) , that was my question. I thought “no, thats not enough to work”. But this was only an (foreign) example i found and try to understand!)
My case:
What I want is a physical push button and a “soft” button in openHAB to activate/deactivate the alarm.
And a LED on a GPIO should show if the alarm is activated or not.
For the physical push-button I have to create a contact item (my name: “AlamHardbutton”) in my contacts.item -file. (correct?)
For the soft-switch I have to create an switch-item on my sitemap (correct?) (this switch-button will/can also show if Alarm is actuall activated or deactivated (correct?))
And the rule (which need to be created) have to check (monitor) the pyhsical button and the soft-button (if activated), than decide: Alarm state is switched from: on=>off or from: off=>on.
And if alarm status is “on”, the LED on GPIO should be get powered on.
Puhhh, I think I need help … my wife expect that the alarm is working soon again because we will go to holiday next week …
Now I can switch on/off the LED (GPIO22) with the soft-button (“switch” in oH), the GPIO_Buttom (GPIO17) I see in the log (so it works physically), but the LED did not change status.
Also not sure if your written statement is correct:
…
GPIO_LAMP.sendCommand(if(GPIO_LAMP.state == ON) ON else OFF)
…
Should it not:
…
GPIO_LAMP.sendCommand(if(GPIO_LAMP.state == ON) OFF else ON)…
I try both versions but both did not change anything on the LED (or switch state in oH)
GPIO_LAMP.sendCommand(if(GPIO_LAMP.state == OFF) ON else OFF)
Alternate if the above does not work as needed.
rule "Alarm"
when
Item GPIO_BUTTON changed
then
if (GPIO_LAMP.state == ON) {
GPIO_LAMP.sendCommand(OFF)
}
else if (GPIO_LAMP.state == OFF) {
GPIO_LAMP.sendCommand(ON)
}
end
Try the alternate rule as the above one liner is more for controlling a pushbutton/relay.
Rule
rule "Alarm"
when
Item GPIO_BUTTON changed
then
if (GPIO_LAMP.state == ON) {
GPIO_LAMP.sendCommand(OFF)
}
else if (GPIO_LAMP.state == OFF) {
GPIO_LAMP.sendCommand(ON)
}
end
Just thought it work …
I can switch the LED off with the phy. button, but not switch on again.
When pressing, the LED is flicker, but every time the LED is “off”. A timing issue from the GPIO?
I add “debounce:50” in the alarm.item -part, but nothing changed:
Contact GPIO_BUTTON “Button [%s]” (LivingRoom) { gpio=“pin:17 debounce:50 activelow:yes” }
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.