Hello,
actuall I have a simple (physical) switch to activate the house alarm.
The code is this:
rule "Alarm"
when Item DoorTerrace changed from CLOSED to OPEN or Item DoorLivingroom changed from CLOSED to OPEN
then
if( Alarmswitch.state == CLOSED )
{
logInfo("contact.rules", "!!! ALARM !!! ")
sendPushoverMessage(pushoverBuilder("Alarm...).withApiKey("d7sdzf86zh...."))
}
end
Hint: The physical switch (“Alarmswitch.state”) it not a push button!
Now I want to have the option to disable (or activate) the alarm from mobile phone (traveling etc.) with a “switch” item in openHAB.
So:
When the physical switch is “on” (=closed; alarm active) the soft-switch should be able to deactivate the alarmsystem.
(and after a physical switch-off => switch-on the alarmsystem should be activated again)
And:
When pysical witch is off (open; deactivated), the soft switch should enable the alarmsystem.
(and after a physical switch-on => switch off the alarmsystem should be disabled again).
Hope the explanations are clear
Will be great if anyone give me a hint how to to proceed here … no so good in rules etc.
Based on the description, physical switch on or off, use the Soft_Switch to control the alarm.
rule "Alarm"
when Item DoorTerrace changed from CLOSED to OPEN or Item DoorLivingroom changed from CLOSED to OPEN
then
if(Soft_Switch.state == ON)
{
logInfo("contact.rules", "!!! ALARM !!! ")
sendPushoverMessage(pushoverBuilder("Alarm...).withApiKey("d7sdzf86zh...."))
}
else
{
sendPushoverMessagesend(pushoverBuilder("Alarm deactivate) withApiKey("xxxxx"))
}
end
Here’s where I’m a bit confused. Is the “switch-on the alarmsystem” the same as the Soft_Switch or something different?
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” }