# Use Z-Wave Thing attributes in a rule

**URL:** <https://community.openhab.org/t/use-z-wave-thing-attributes-in-a-rule/104014>\
**Category:** Tutorials & Examples\
**Tags:** jython, zwave, scripted-automation\
**Created:** [August 23, 2020, 3:40am UTC](https://community.openhab.org/t/use-z-wave-thing-attributes-in-a-rule/104014 "2020-08-23T03:40:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![5iver](https://community.openhab.org/user_avatar/community.openhab.org/5iver/32/21201_2.png) [@5iver](https://community.openhab.org/u/5iver)\
**Post date:** [August 23, 2020, 3:40am UTC](https://community.openhab.org/t/use-z-wave-thing-attributes-in-a-rule/104014/1 "2020-08-23T03:40:13Z")

</div>

> [@ZWave binding updates](https://community.openhab.org/t/zwave-binding-updates/51080/1089):
>
> Is it possible to access zwave thing attribues ‘last\_wakeup’ and ‘last\_heal’ from openhab rules ?
> 
> Also, how can I enumerate attributes of specific thing?

> [@ZWave binding updates](https://community.openhab.org/t/zwave-binding-updates/51080/1091):
>
> You can use REST, but this is entirely possible using scripted automation. Let me know if you’d like an example

> [@ZWave binding updates](https://community.openhab.org/t/zwave-binding-updates/51080/1095):
>
> I’d be grateful if you can share one.

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!

```auto
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))

```

---

<div class="post-metadata">

**Author:** ![rdslw](https://community.openhab.org/user_avatar/community.openhab.org/rdslw/32/72243_2.png) [@rdslw](https://community.openhab.org/u/rdslw)\
**Post date:** [August 23, 2020, 6:42pm UTC](https://community.openhab.org/t/use-z-wave-thing-attributes-in-a-rule/104014/2 "2020-08-23T18:42:27Z")

</div>

THanks, I understand it requires jython jsr223 installation and configuration like described here: [https://www.openhab.org/docs/configuration/jsr223-jython.html](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?

---

<div class="post-metadata">

**Author:** ![5iver](https://community.openhab.org/user_avatar/community.openhab.org/5iver/32/21201_2.png) [@5iver](https://community.openhab.org/u/5iver)\
**Post date:** [August 23, 2020, 7:32pm UTC](https://community.openhab.org/t/use-z-wave-thing-attributes-in-a-rule/104014/3 "2020-08-23T19:32:37Z")

</div>

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…

> [@\[beta testers wanted!\] Jython addon w/ helper libraries (requires OH 2.5.x)](https://community.openhab.org/t/beta-testers-wanted-jython-addon-w-helper-libraries-requires-oh-2-5-x/86633):
>
> I just submitted a PR that adds a core feature for a JythonScriptEngineFactory and it would be great to have some testers! Basically, this will allow for the installation of Jython including the core and community helper libraries through Paper UI, once the PR is merged. If you’d like to test it, you’ll need to… Have OH 2.5.x (S1778) or newer Shutdown OH Backup OH [Download the addon](https://drive.google.com/drive/u/1/folders/1Bixyq9GqUQA7bmoRW89mH3WHM5KKSjiY) and copy to $OPENHAB\_HOME/addons/ ([see here](https://www.openhab.org/docs/installation/linux.html#file-locations) for more details). The jar contains the core and community helper li…

Manual instructions are here…

> **[Helper Libraries for openHAB Scripted Automation — openHAB Helper Libraries ...](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.

---

<div class="post-metadata">

**Author:** ![rdslw](https://community.openhab.org/user_avatar/community.openhab.org/rdslw/32/72243_2.png) [@rdslw](https://community.openhab.org/u/rdslw)\
**Post date:** [August 23, 2020, 9:40pm UTC](https://community.openhab.org/t/use-z-wave-thing-attributes-in-a-rule/104014/4 "2020-08-23T21:40:15Z")

</div>

Wow. It works.

I went easier (? 🙂 ) 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)](https://community.openhab.org/t/beta-testers-wanted-jython-addon-w-helper-libraries-requires-oh-2-5-x/86633)):

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!

---

<div class="post-metadata">

**Author:** ![5iver](https://community.openhab.org/user_avatar/community.openhab.org/5iver/32/21201_2.png) [@5iver](https://community.openhab.org/u/5iver)\
**Post date:** [August 24, 2020, 2:27am UTC](https://community.openhab.org/t/use-z-wave-thing-attributes-in-a-rule/104014/5 "2020-08-24T02:27:43Z")

</div>

> [@rdslw](#):
>
> I went easier (? 🙂 ) route and put 2.7.0 jar, not using bundle.

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 🙂! 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.

> [@rdslw](#):
>
> For example in bundle approach if I may suggest two things to correct in your top post

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

> [@rdslw](#):
>
> Once again, thank you kindly for your work @5iver, I appreciate it!

You are very welcome… I am happy to help!

---

<div class="post-metadata">

**Author:** ![system](https://community-openhab-org.s3-eu-central-1.amazonaws.com/original/2X/6/6a52f2ac5d00e4c7b50471a354b3a9221188be90.png) [@system](https://community.openhab.org/u/system)\
**Post date:** [October 4, 2020, 6:27pm UTC](https://community.openhab.org/t/use-z-wave-thing-attributes-in-a-rule/104014/6 "2020-10-04T18:27:44Z")

</div>

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