JRuby OpenHAB Rules System

DECREASE is a native command, and it’s up to the binding (or your own rules if it’s a virtual or proxy item) to determine how it’s handled. Some bindings have a native way to pass such information on, allowing a completely race condition free way to lower the level on the device. I think a lot of bindings simply simulate it, and when they get DECREASE they take their current state, subtract a given amount (say 1 or 5), and then pass on the final value to the device. This is how the MQTT binding works (though being able to configure the channel to directly pass on such commands is on my own internal wish list).

The same is true of (UP/DOWN/STOP) Rollershutter commands. Some bindings can pass those natively to a device, while others translate them to (0/100/current known state) before passing them on.

So there’s no openhab-default fallback behaviour for this in the case that the binding doesn’t handle it?

That makes me sooo happy. I normally suck at writing docs. And making things pretty. But @JimT and I put in a lot of work to make the docs as complete and usable as possible. We’re often making improvements. Also please file issues (or send PRs!) if you come across something unclear or lacking details.

Is it possible to get a thing’s property via an item?

I have Shelly1 devices with a temperature sensor which I use to control the floor heating. When the desired temperature is changed I need to do REST calls in order to set the overtemp and undertemp thresholds. For these I need the IP address of the thing. I could create a hash map inside the rule file looking up the IP addresses but come on… where is the fun if this information is already stored inside the thing?

Pseudo code would be:
ipAddress = event.item.theThingOfThisItem.property("deviceIp")

See here regarding the Thing properties:
https://next.openhab.org/addons/bindings/shelly/#thing-configuration

Yes.

event.item.thing.properties["deviceIp"] should work.

References:

I was close ^^

But the IP is not part of the properties I just realized. For future readers here is how to get the IP address of a Shelly thing: <shellyItem>.thing.configuration.get("deviceIp")

1 Like

You can also treat the configuration as a Ruby hash: item.thing.configuration["deviceIp"]

References:

https://openhab.github.io/openhab-jruby/main/OpenHAB/Core/Configuration.html

Even better!

Nope, this does not work.
So this line works:
thermostat.points(Semantics::Switch).first.thing.configuration.get("deviceIp")
but this one throws:
undefined method `[]' for #<Java::OrgOpenhabCoreConfigCore::Configuration:0xae5338> (NoMethodError)
at line
thermostat.points(Semantics::Switch).first.thing.configuration["deviceIp"]

This syntax was supported in 5.6.0 released yesterday. An openhab restart should upgrade yours.

Yup. Now it works.

Next question :no_mouth:
Is this trigger

rule "Switch on pump" do
    cron hour:6-8, minute: 0/30
    cron hour:9-21

the same as this RuleDSL trigger condition?

rule "Switch on pump"
when
	Time cron "0 0/30 6-8 ? * * *" or
	Time cron "0 0 9-21 ? * * *"

The value given to the arguments need to be strings when they are not simple numeric, otherwise they’ll be interpreted as arithmetic expressions, i.e. 6-8 = -2, and 0/30 = 0.

To achieve what you want:

rule "Switch on pump" do
    cron hour: "6-8", minute: "0/30" # => `0 0/30 6-8 ? * ? *`
    cron hour: "9-21" # => `0 0 9-21 ? * ? *`

We should totally support ranges here, though.

1 Like

Great idea!

Now this syntax is also supported in 5.6.1:

cron hour: 6..8, dow: :MON..:FRI, month: "JAN".."MAR"

Thanks guys :sunglasses:

How to invoke a scene in Jruby? Is this possible?

scenes[“scene_id”].trigger

so…

after(30.minutes) do
scenes[“SunsetAfter”].trigger
end

image
Yes?

Yes

1 Like

it’s rules.scenes["sceneuid"].trigger but since scenes are basically rules, you could also use rules["sceneuid"].trigger