I’ve been porting DSL rule files to the new UI based configuration but I have a problem: I don’t know how to share timers between rules.
In my actual setup I declare the timer with global scope and put all rules in the same file.
I don’t know how you can achieve same functionality using the UI. It’s a pretty common use case I think?
@hmerk is correct, there is no way to share variable between rules. In fact there isn’t even a way to share variables between Script Actions and Script Conditions within the same rule.
There is an issue open and a discussion about how to handle this but it’s not see much action in awhile so I don’t know how long we need to wait. Theoretically it should be possible to do it now but I’ve not yet figured out how to do it.
While it is a common used case in Rules DSL, it’s not always necessary. Often the rules can be combined or Expire can be used instead. However, one gotcha is that Rules DSL does not support an operator to test whether a variable exists or not. Because of that we don’t have a way to preserve the state of a variable from one run of a rule to the next. Consequently, often to work with Timers in UI rules one needs to use JavaScript or one of the other rules languages.
Yes you are right, but I prefer my rules to be clean than combine them with unsightly if-then-else or case control statements. In fact I do like rules to be very short if possible.
Openhab has a very powerful rule engine and perhaps this is too much to ask. I will migrate those rules that can be configured w/o using scripts, with are the majority.
That’s a good choice a lot of the time. If using a language other than Rules DSL one can access Item metadata as well which can be convenient. For example, I have some lights that are controlled by time of day. However, if the light is manually controlled during the day, the automation is turned off. I determine whether or not to turn on or off the automation using a flag stored in the Item metadata.
However, you can’t really store or manage a timer in an Item except through the Expire function which is not universally applicable to all use cases.