I don’t think there is an easy way to get the Thing’s status inside a rule in Rules DSL like you can in other languages (including Blockly) and there definitely isn’t a way to disable a rule from Rules DSL like other languages.
If you stick with Rules DSL, you’ll have to create another rule that triggers when the Thing changes status and update an Item. Then I’m this rule have an if statement that checks that Item.
In any of the other languages you can add an if statement that checks the status of the Thing directly.
In the UI, if statement would go in the “but only if” part of the rule.
With the other languages you also have the option and actually disabling the rule, but like with the Item approach, you’ll need another rule that triggers on state changes of the Thing and enables/disables the rule accordingly. But with this approach in the UI, you wouldn’t even need any code at all.
I have so many things remaining in my openhab todo list…
I was going to switch to something better when I have upgraded to OH3.3, but issues, memory leaks and so on made me postpone everything.
For OH4.x what would be the best language for rules ?
(I know this question can be an endless debate but…)
JS Scripting - this is the most popular and most used. Plenty of examples and plenty of people to help you
JRuby - IMO, this is the easiest and nicest language + helper library to work with, and also possibly the most powerful. It is much nicer to work with Ruby compared to JS. It has a comprehensive documentation too. But not as many people use it and there aren’t as many posts about it either. Currently the latest version of the helper library supports OH versions from 3.4 all the way to 4.2-snapshot. So you can actually use JRuby now before upgrading to OH4 and you’d get the latest version of the helper library with it. Upgrading to the latest helper library is easy, just restart openhab or restart the automation addon. You can also install third party libraries easily, much easier than in JS.
This is easy, and can be done in jsscripting or jruby. I don’t know the syntax in js, but in jruby:
rule "AWtrix app temp update" do
cron "0 0/10 9-20 ? * * *"
only_if { things["mqtt:topic:backporch-pir"].online? }
run do
logger.info("Updating awtrix app temp...")
end
end
The only_if is merely a syntactic sugar. You could do the same in this manner:
rule "AWtrix app temp update" do
cron "0 0/10 9-20 ? * * *"
run do
next unless things["mqtt:topic:backporch-pir"].online?
logger.info("Updating awtrix app temp...")
end
end
JRuby offers ways to make cron triggers easier to write
rule "xxx" do
cron minute: "0/10", hour: "9-20"
...
end
You could also do this, although not quite the same in implementation (it sets a cron job that triggers every 10 minutes around the clock, and each time it triggers, it checks whether the time is between 9am and 8pm)
rule "xxx" do
every 10.minutes
between "9am".."8pm"
...
end
no way (no offense ): Blockly (precisely not a language) is definitely the easiest among them… and yet powerful.
And you can include any code from JavaScript-examples too.