Hello again indeed making progress. Let’s put the UI defined rules off to the side for a minute and continue on with getting the file based rules working. From what I have observed in the UI it should indeed work as you state, the triggers are translated into a rule and the rest of the script is then called when the trigger is activated.
I think the test you introduced for sub scenario 2.1 would do the trick. As for sub scenario 2.2 it totally makes sense that that rule would never really work as I intended. I think I may have been working on the indentation assumptions from python, where the while loop is inside the rule not outside.
After reading through Installation — openHAB Helper Libraries documentation on a hunch I put a test rules file in this location:
/openhab/conf/automation/jsr223/ruby/personal/
which does get the rule file loaded, while this location:
/openhab/userdata/automation/jsr223/ruby/personal
does not
So this is pretty exciting for me. But what I am trying to achieve may still be out of my reach. What I am looking for is something like the example:
rule "Execute rule when item is changed for specified duration" do
changed Alarm_Mode, for: 20.seconds
run { logger.info("Alarm Mode Updated")}
end
But I need the rule to fire every time the item stays changed for X seconds, for as long as the item is changed. So if I try to make an example for what that would look like, then it would be something along the lines of:
rule "Execute rule when item is changed a multiple of a duration" do
changed Alarm_Mode, for: every: 20.seconds
run { logger.info("Alarm Mode Updated")}
end
I would suggest that seconds not be limited to being a integer type, but be a double type so that units of time less than one second can be measured, or used in timing. This could be useful for blinking status lights, or increasing a dimmer when a button is held.
I think it would seem more natural if the operator every
would be every:
like at:
, and if the time units were week
instead of :week
, and thereby one could simply make multiples of each of the time units by adding an ‘s’ to the end of each as in weeks
rule 'Log an entry at 11:21' do
every :day, at: '11:21'
run { logger.info("Rule #{name} run at #{TimeOfDay.now}") }
end
would then become
rule 'Log an entry at 11:21' do
every: day, at: '11:21'
run { logger.info("Rule #{name} run at #{TimeOfDay.now}") }
end
or if that is too often
rule 'Log an entry at 11:21 every second day' do
every: 2.days, at: '11:21'
run { logger.info("Rule #{name} run at #{TimeOfDay.now}") }
end