Multi Zone Home Alarm Script for openHAB

Each sensor has a sensorClass defined in the configuration. It can either A or B.

A, sensor can be tripped in both arming modes. E.g. “Armed Home” and “Armed Away”.
B, sensor can be tripped in arming mode “Armed Away” only.

For example if you stay at home and arm “Armed Home” when (e.g. you go to sleep) you probably don’t want PIR motion sensors to trigger an alert if you happen to walk around in your house in the middle of the night for whatever reason. So, set those sensors to sensorClass B. At the same time you want to be aletered if someone opens the front door (set those sensors to sensorClass A.)

See: https://openhab-scripters.github.io/openhab-helper-libraries/Python/Community/ideAlarm/Glossary.html

1 Like

Thanks for the clearification. That will certainly be helpfull. Should have read the glossary more carefully… :blush:

During installation of the core, in the step 11 where it says to download the jar file “Download the standalone Jython 2.7.0 jar”, the page is not found. Is this a mandatory step?? Is there some alternative??
Edit: Found correct link is standalone Jython 2.7.1 jar. Should I go for 2.7.1 instead of 2.7.0. Or should I find the recommended version 2.7.0 instead??
In the meantime I am installing 2.7.0 from the page https://mvnrepository.com/artifact/org.python/jython-standalone/2.7.0

Okay the 11th step went well. i could not understand the step 12 though.It says "Copy the /Script Examples/Python/hello_world.py script to /automation/jsr223/python/personal/"
But where is the hello_world.py file. I am really confused now. What am I missing
Just to add, this is the log output

2019-11-29 22:19:32.880 [INFO ] [openhab.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2019-11-29 22:19:33.979 [INFO ] [b.core.service.AbstractActiveService] - Expire Refresh Service has been started
2019-11-29 22:19:35.656 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = f4ded7d9-b9c1-4dc9-8572-df25a155f1b5, base URL = http://localho$
2019-11-29 22:19:35.895 [DEBUG] [.AutomationResourceBundlesEventQueue] - Process bundle event 2, for automation bundle 'org.openhab.core.automation'
2019-11-29 22:19:35.905 [DEBUG] [vider.AbstractResourceBundleProvider] - Parse rules from bundle 'org.openhab.core.automation'
2019-11-29 22:19:35.904 [DEBUG] [.AutomationResourceBundlesEventQueue] - Process bundle event 32, for automation bundle 'org.openhab.core.automation.module.script.rulesupport'
2019-11-29 22:19:35.910 [DEBUG] [vider.AbstractResourceBundleProvider] - Parse rules from bundle 'org.openhab.core.automation.module.script.rulesupport'
2019-11-29 22:19:36.231 [DEBUG] [e.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added CoreModuleHandlerFactory
2019-11-29 22:19:36.235 [DEBUG] [e.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added EphemerisModuleHandlerFactory
2019-11-29 22:19:36.239 [DEBUG] [e.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added TimerModuleHandlerFactory
2019-11-29 22:19:36.243 [DEBUG] [e.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added AnnotatedActionModuleTypeProvider
2019-11-29 22:19:36.367 [DEBUG] [e.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added AnnotatedThingActionModuleTypeProvider
2019-11-29 22:19:36.495 [DEBUG] [e.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added MediaModuleHandlerFactory
2019-11-29 22:19:36.638 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added GenericScriptEngineFactory
2019-11-29 22:19:36.651 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngineFactory details for Oracle Nashorn (1.8.0_232): supports ECMAScript (ECMA - 262 Edition 5.1) with $
2019-11-29 22:19:36.655 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added NashornScriptEngineFactory
2019-11-29 22:19:36.658 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngineFactory details for Oracle Nashorn (1.8.0_232): supports ECMAScript (ECMA - 262 Edition 5.1) with $
2019-11-29 22:19:36.664 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Removed GenericScriptEngineFactory
2019-11-29 22:19:36.667 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Removed NashornScriptEngineFactory
2019-11-29 22:19:36.737 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added GenericScriptEngineFactory
2019-11-29 22:19:36.741 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngineFactory details for Oracle Nashorn (1.8.0_232): supports ECMAScript (ECMA - 262 Edition 5.1) with $
2019-11-29 22:19:36.744 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added NashornScriptEngineFactory
2019-11-29 22:19:36.747 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - ScriptEngineFactory details for Oracle Nashorn (1.8.0_232): supports ECMAScript (ECMA - 262 Edition 5.1) with $
2019-11-29 22:19:36.752 [DEBUG] [e.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added ScriptModuleHandlerFactory
2019-11-29 22:19:36.842 [DEBUG] [e.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added ScriptedCustomModuleHandlerFactory
2019-11-29 22:19:36.868 [DEBUG] [e.automation.internal.RuleEngineImpl] - ModuleHandlerFactory added ScriptedPrivateModuleHandlerFactory
2019-11-29 22:19:43.387 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Error during the execution of startup rule 'Start Bauts Power1': 'plusSeconds' is not a member of 'null'; line$
2019-11-29 22:20:01.951 [INFO ] [me.core.service.AbstractWatchService] - Loading script 'javascript/core/000_startup_delay.js'
2019-11-29 22:20:05.647 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language 'js' with identifier: file:/etc/openhab2/automation/jsr223/javascript/core/000$
2019-11-29 22:20:05.969 [INFO ] [jsr223.javascript.core.startup_delay] - Checking for initialized context
2019-11-29 22:20:06.097 [INFO ] [jsr223.javascript.core.startup_delay] - Context initialized... waiting 30s before allowing scripts to load
2019-11-29 22:20:36.209 [INFO ] [jsr223.javascript.core.startup_delay] - Complete

Update: Okay I found the script in Examples Folder.

Jython isn’t mandatory, but since most of the code snippets you will find around is Python, I would recommend it.
I believe 2.7.1 is fine, Remember to update the extra_opts accordingly

Hi !
I have posted the logs. Please have a quick look if that looks fine to you

Your logs is indicating that Jython isn’t running as you also write. As @RRoe wrote, each step in the install guide is there for some reason. If not done, then something would probably not work as expected.

Okay I think I should make a separate post to get help on this. Once it clears out, I’ll follow the rest of steps. Thanks

FYI… I plan to submit a PR this weekend for OHC that will include Jython and the helper libraries as an optional feature that can be installed through Paper UI. The installation will be much much much simpler :smile:! If you do create another post to get help with the installation, setup or beginner questions, please tag it with jsr223 so that others will be notified of your post (and feel free to @ me).

3 Likes

Thanks a ton for that. Really great. I hope it gets merged in the coming 2.5 release or maybe in the coming milestone. Fingers crossed.

Thanks I would do that today.

1 Like

Actually, I see that the part of the documentation that describes the configuration is missing. I’ve created a github issue on the topic. The old wiki documentation of ideAlarm that describes the configuration has not yet been migrated to the new documentation.

2 Likes

Excited about getting ideAlarm going - I think I am almost there, but using the Sitemap via the OpenHab iPhone app, the system won’t go to Arm status when I toggle one of the two arming modes.
I’ve checked and rechecked correct object locations, persistence, map files, parsed configuration.py through python buddy, etc.
The items report via the App sitemap:
Z1 open sections 1
Z1 Arming Mode: Disarmed
Z1 Status: Normal

in my logs the most suspicious thing I see is:
2020-02-17 09:38:04.983 [INFO ] [me.core.service.AbstractWatchService] - Loading script ‘python/community/idealarm/idealarm.py’

2020-02-17 09:38:04.987 [DEBUG] [ipt.internal.ScriptEngineManagerImpl] - Added ScriptEngine for language ‘py’ with identifier: file:/etc/openhab2/automation/jsr223/python/community/idealarm/idealarm.py

2020-02-17 09:38:11.042 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/etc/openhab2/automation/jsr223/python/community/idealarm/idealarm.py’: ImportError: No module named idealarm in at line number 2

Sounds like the files are not copied to the right directories. What do you see returned from…

tree ${OPENHAB_CONF}/automation/lib/python/community/idealarm

BTW, if you were to use the beta Jython bundle, this library would be installed for you. Core and community helper libraries are included in the bundle.

1 Like

I get this:
/etc/openhab2/automation/lib/python/community/idealarm

└── init.py

OK… so the file is in the right place, but the account that runs OH can’t see the file. Check the permissions?

ls -al ${OPENHAB_CONF}/automation/lib/python/community/idealarm

drwxrwxr-x 2 openhab openhab 4096 Feb 17 10:44 .

drwxrwxr-x 3 openhab openhab 4096 Feb 17 10:38

-rw-rw-r-- 1 openhab openhab 27061 Feb 12 10:17 init.py

OK… the account has permissions to it. Do you have any other scripts that use the helper libraries and are they working properly? The last thing I can think of is to check sys.path. Put this into a test script…

from core.log import logging, LOG_PREFIX#, log_traceback
LOG = logging.getLogger("{}.TEST".format(LOG_PREFIX))

import sys
if hasattr(sys.version_info, "major"):
    LOG.warn("Jython version [{}.{}.{}.{}]".format(sys.version_info.major, sys.version_info.minor, sys.version_info.micro, sys.version_info.releaselevel))
LOG.warn("Jython version [{}]\n".format(sys.version))
LOG.warn("sys.path [{}]".format(sys.path))

One other thought… do you have a community package? What’s in…

ls -al ${OPENHAB_CONF}/automation/lib/python/community

(should be an empty __init__.py)

Just did a chmod to 777 and that seemed to do it, watching the rules fire now, sitemap disappeared in meantime - Thanks for your help! I think I am almost there !!

1 Like

Oh and regarding the community package - I DID have that missing earlier, but repaired it - good idea

1 Like

And - YES - it works nicely!!!