Use Z-Wave Thing attributes in a rule

Here you go, @rdslw. I left in some of the things that I used to figure out what was needed. I’m not sure how you were planning on getting to the Thing, so this just iterates through all of the Z-Wave Things. Let me know if you need anything else!

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

for thing in [thing for thing in things.all if thing.UID.toString().split(":")[0] == "zwave"]:
    #LOG.warn(dir(thing))
    #LOG.warn("thing.label: {}\nthing.UID: {}\nthing.configuration: {}\nthing.properties: {}\n".format(thing.label, thing.UID, thing.configuration, thing.properties))
    #LOG.warn(thing.properties)
    #LOG.warn(type(thing.properties))
    #LOG.warn("zwave_lastheal: {}, zwave_lastwakeup: {}".format(thing.properties.get("zwave_lastheal"), thing.properties.get("zwave_lastwakeup")))
    for zwave_property, value in thing.properties.items():
        LOG.warn("{}: {}".format(zwave_property, value))
5 Likes

THanks, I understand it requires jython jsr223 installation and configuration like described here: https://www.openhab.org/docs/configuration/jsr223-jython.html

  1. correct?
  2. can I use jython 2.7.2 ?
  3. is it possible to do without jython, or whole things.all etc are not available in standard rules?

This uses scripted automation, included with the new rule engine, and Jython, but you could use any supported scripting language. The documentation, examples, and helper libraries for Jython are much more advanced. Here is a beta add-on to simplify the installation…

Manual instructions are here…

https://openhab-scripters.github.io/openhab-helper-libraries/index.html

There is an update coming for the docs… I recommend 2.7.2. This functionality is not available in the rules DSL.

Wow. It works.

I went easier (? :slight_smile: ) route and put 2.7.0 jar, not using bundle. I found your support very helpfull, thank you!

It wasnt so easy to enable it, due tu multiple information, which seemed to me (not having experience with java in general) contradictory.

For example in bundle approach if I may suggest two things to correct in your top post ([beta testers wanted!] Jython addon w/ helper libraries (requires OH 2.5.x)):

  1. add section, what is NOT needed:
    a. no need to instal NGRE (or if needed put it as a step) -> this is something which make me resign trying bundle, as I did not understand it
    b. no need to change /etc/default/openhab2 EXTRA_JAVA_OPTS (this was asked multiple times by oldtimers in the long thread, but its missing from top post)
  2. explain in more clarity sentence “The jar contains the core and community helper libraries, so there’s no need to copy them from the repo. However, the core scripts will need to be copied to /automation/jsr223/python/core/.” - I still do not understand difference in ‘core helper libraries’
    vs ‘core scripts’. Documenting it a bit longer would be helpful, especially if do not know if this step is needed or not, and what exactly is needed. I would separate here things MUST to do (to put in first list), with the things NOT needed to do (like 1a 1b above).

Once again, thank you kindly for your work @5iver, I appreciate it!

The beta add-on is definitely easier than the manual installation, since you do not need to mess with EXTRA_JAVA_OPTS or to copy in any libraries. If you had questions or issues, you should have asked :slightly_smiling_face:! The only thing needed is to copy in the core scripts (everything in /automation/jsr223/python/core/), but these are only needed if you use them.

As I have said, I have doc updates to push. These include updates to the installation, including steps for using the add-ons.

You are very welcome… I am happy to help!

2 Likes

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.