I have a rule that sends me an email and plays a sound when my door sensor switches open/closed. I would like to have a button in Habpanel that will enable or disable this rule. Is this possible?
Here is my current rule
rule “FrontDoorDogEmail"
when
Item FrontDoor changed from CLOSED to OPEN
then
sendMail("xxxxxx@xxxxx.com”, “Alert-Front Door Opened”, “Front Door is OPEN and dogs are attacking”)
executeCommandLine(“aplay /srv/openhab2-conf/sounds/dog45.wav”)
end
rule “FrontDoorDogEmail” when
Item FrontDoor changed from OPEN to CLOSED
then
sendMail("xxxxxx@xxxxx.com", “Alert-Front Door Closed”, “Front Door is now Closed”)
Yes,
This is possible. See example below.
You need to create a new switch item (in this example called “YOURNEWSWITCH”) which you can switch on/off.
rule "FrontDoorDogEmail"
when
Item FrontDoor changed from CLOSED to OPEN
then
if (YOURNEWSWITCH.state == ON) {
sendMail("xxxxxx@xxxxx.com", "Alert-Front Door Opened", "Front Door is OPEN and dogs are attacking")
executeCommandLine("aplay /srv/openhab2-conf/sounds/dog45.wav")
} else {
/* Do Nothing */
}
end
The rule by itself could not be disabled, but you should be able to create a virtual switch in OH and with this switch you can disable the mail and sound commands
rule "FrontDoorDogEmail" when
Item FrontDoor changed from OPEN to CLOSED
then
if (EnableSwitch.state == ON) then {
sendMail("xxxxxx@xxxxx.com", "Alert-Front Door Closed", "Front Door is now Closed")
}
end