If/Else in a rule does.. both?!

Back, and found a way to get around the issue : don’t use else. I can use AND/OR in the if statements and cover the conditions needed and everything works reliably.

Clearly, the variable/group/item switches aren’t all treated the same way in the base code.

The following works just fine:

rule "alarm front door"
       Item AlarmFrontDoor changed from ON to OFF
        if (switchArrived.state == ON) {
                 say("Welcome home!", "pollytts:Salli", "enhancedjavasound")
        if ((switchArrived.state != ON) && (groupPresence.state == ON)) {
                say("the front door has been opened", "pollytts:Salli", "enhancedjavasound")
        if ((switchArrived.state != ON) && (groupPresence.state == OFF)) {
                //alarm trigger
                sendXMPP("email1@mail.com", "The front door has been opened!")
                sendXMPP("email2@mail.com", "The front door has been opened!")
        //arrfdoor.sendCommand(ON) //doesn't work reliably

@rossko57 - indeed, I’m running on an laptop, an i5 with 16 gig RAM and utilizing a RAMDrive on /tmp so all logs and log parsing never really hits the SSD drive. It’s a quick little sys.

Also in the code above you’ll see a reference to the exec extension that allows execution of external scripts : I was going to take care of all this with an external Python program; while it worked perfectly on the command line it wasn’t reliably executed from the rule. I ran into the same problem as divanshu6467 using executeCommandLine:

I tried using the exec binding but sometimes it logs as run, sometimes it doesn’t and I never got audio due to SystemD audio daemon permissions (I loathe SystemD, rant #12). Just as an FYI, here’s my python3 script:

#apt install python3-pip
#pip install python-openhab
from openhab import openHAB
import time
import subprocess
import logging

haburl = ''
say = "/etc/openhab2/python/saysomething.py"

debuglevel = 9

openhab = openHAB(haburl)

arrived = openhab.get_item("switchArrived")
present = openhab.get_item("groupPresence")
logging.info('arrived: ' + str(arrived))
logging.info('present: ' + str(present))
if "ON" in str(arrived):
    subprocess.run([say,"welcome home!"])
elif "ON" not in str(present):
    # alarm state
    subprocess.run([say,"alarm state!"])
    subprocess.run([say,"the front door has been opened."])

So, case closed, it now works but not the way it should,