[OH2] Read property of a thing in rule


I’m trying to read zwave device’s last wakeup time in my rules - can this be done?

In PaperUI, this is under the “SHOW PROPERTIES” of the thing/node (and the actual property is called “zwave_wakeup_time”).

Any hints, please?

Thanks, Paweł

No. Rules only have access to Items. If there is not a channel that exposes that information you can’t get it within your rules.

is there any other method available? my hue lights (things) are reported as online/offline in the events.log, like:

'hue:0100:00178873ef40:2' changed from OFFLINE: Hue bridge reports light as not reachable. to ONLINE

I’d like to react on this in a rule. Or can I create an item, based on the information above? unfortunately no channel that shows this status.


1 Like

As a workarround I developed a rule function to get the last wakeup time from a zwave device:

val Functions.Function1<String, DateTime> getZwaveLastPacketReceived = [
    String nodeUid |
    	var String url = String::format("", nodeUid)
  		var String json = sendHttpGetRequest(url)
		var String lastPacketReceived = transform("JSONPATH", "$.properties.zwave_wakeup_time", json)
		var DateTime dtLastPacketReceived = parse(lastPacketReceived)
		return dtLastPacketReceived.withZone(DateTimeZone::getDefault());

The function is used like this:

var DateTime lastPacketReceived = getZwaveLastPacketReceived.apply("zwave:device:4c0da5c0:node12")

I’m using this function to set a datetime variable using a cron rule.

@chris: Is this still the only way to access thing properties in a rule or is there now an official api for this?

As far as I know there’s no other way to do this, but I’ve not kept up with changes to the rule system so I could be wrong.

Are there any updates (related to version 2.3)? I’m developing the Rachio sprinkler binding, which provides some useful information (like the Geo location of the controller). This information is static, so no need for a channel providing live data. Getting access to thing properties from a rule would allow to use this information rather than implementing a ton of channels, which never change and confuse the user on binding usage.

Hi Chris, I just did take a look at the Eclipse Smarthome code to see if something was added to access the Thing parameters in the meantime. I didn’t find anything that is explicitly build to access the parameters, but maybe I found something that could be used for this. There is a getActions command that can be called inside the rules to get actions for every Thing. Here is an example from the MQTT addon: https://github.com/openhab/openhab2-addons/blob/07faf6f96d95079d1a8b3c49f27308813441c452/addons/binding/org.openhab.binding.mqtt/src/main/java/org/openhab/binding/mqtt/action/MQTTActions.java

I also think it should be possible to return values with this system. Here is something I found in the smarthome repository: https://github.com/eclipse/smarthome/blob/e25f1bd548126ef44fbdc90dd1dd0f85e83bdef0/bundles/test/org.eclipse.smarthome.magic/src/main/java/org/eclipse/smarthome/magic/binding/internal/automation/modules/MagicMultiServiceMultiActions.java

Do you know this command and would it be possible to build a “getParameters” Action for ZWave things with this to get the parameters in the Rules?

Are there any updates on accessing the Thing properties and/or config with OH3? Seeing no obvious way doing this on a hue motion sensor.

Thank you

@5iver Thanks for your quick feedback!

I have to say, that this isn´t quite the solution I was looking for.

If I get it right, this is some next gen script, which scans the log for a certain thing attribute and outputs the respective log entry as the item state?!

My hope was, that there is a bit more dynamic and repeatable approach for this. This may be a problem of my technical understanding but I don´t realy get why it seems that hard to access these attribute / parameter details if there are already shown in the ui - and this seems to be a thing for a long time now.

So maybe theres not that much interest in this feature, to prioritize it as a feature for v3?

I am grateful for all explanations on this topic.

Partly it’s about “why would you want to look at a Thing?”, at least in the everyday context anything the home automation stuff is interested in should be accessible as an Item.

You can use REST API to examine Thing properties on demand.

1 Like