How does the now variable come into existance

I’ve found several scripts that refer to a now global variable, that I assume contains the current date and time. How does this value get defined? I’m assuming its a global variable. I started looking through the Openhab source code and found where numerous other globals are defined, but not this one.

As a general follow up question, other than the source, is there documentation for the commonly imported libraries and global variables?

tl;dr now is one of the implicitly defined variables the Rules Engine provides for you. Others include receivedCommand, previousState, and a reference to all Items and Groups.

OH documentation can be found in the wiki.

Longer explanation:

The OH Rules Engine is a Domain Specific Language based on Xbase and has the most in common with the Xtend language in syntax and capabilities. But, given that it is a DSL, the language provides a number of things for you that would not be available in a general purpose programming language. Implicit variables are one of those things that it provides. These include:

  • now - gives you a Joda DateTime object that represents the current time
  • receivedCommand - if you have a rule that triggers using a “received command” based trigger, this variable will contain the command received
  • previousState - if you have a rule that triggers using a “changed” trigger this variable will be populated with the previous state of the Item that triggered the rule
  • Items and Groups - you can reference all your Items and Groups by name

Some of this is documented in the Rules wiki page but I actually don’t see now documented there. Perhaps it needs to be added.

All that being said, if you can’t find an answer to something you want to know in the wiki, the next place to look are the examples. If you can’t find an example for what you want to do the next place is to ask a question on this forum. The code could be a good place to look but it takes a long time to learn the structure and organization of everything.

Thank you.