[OH2] Read property of a thing in rule

Hi,

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.

Stefan

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("http://127.0.0.1:8080/rest/things/%s", 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?