There is a fundamental misunderstanding about how OH works.
There is the Rules DSL. Vincent posted a link to a reference for that. Though the Rules page on the docs is probably the more appropriate first stop because you are not having issues with just the Rules, but fundamental understanding of OH.
There are extensions to the base language that add commands to the language. These extensions are called Actions. createTimer is one example of just such an extension. You won’t find it in a reference to the language because it isn’t part of the language.
OH integrates and allows users to work with 330+ technologies and APIs. Each and every one of these technologies and APIs work differently in how one configures and uses them in OH. It’s the fragmented reality that we live in in this problem space. If you are expecting to be able to use something that can bridge between 330+ APIs you have to understand at least a little bit about the API you are working with or you will be disappointed.
MQTT isn’t a language. It’s one of those 330 APIs that OH integrates with. The publish Action you found is an extension to the Rules DSL and is one of the ways you can integrate with MQTT. You have to install it and the documentation for this extension is under Add-ons Actions MQTT.
If you want to use a library to talk to a DHT22 sensor from Adafruit, you don’t expect to find the docs for that library in Straustrup’s C++ Reference? There same applies here. Actions and Bindings are like that library.
OH is a while ecosystem, it’s not just a programming language. If you try to approach it like it is just a language you will be disappointed.
Have you spent any time looking at the openHAB docs themselves? Because really you are not looking for a language reference, you are looking for an openHAB reference and openHAB is so much more than just it’s Rules DSL.
At this stage you should be looking at the Beginner’s Tutorial (incomplete but better than nothing), the concepts section of the docs, and the Rules section of the docs. From these you should understand what a Thing, Channel, Item, Binding, Sitemap, Persistence, and Action are. You should also understand how to structure your rules file syntactically for the most part. The Xtend docs are linked to from the Rules page and a few users find use in it, but the vast majority never look at it nor need to.
You should also be looking at the Demo config and playing around with that too start with.
If after going through all that if you still don’t know where to look then issues need to be filled.
In that frustrating amount of time in the Xtend docs have you read the lambda page yet? The [ | ] are used to define a lambda, a method that is encapsulated in an object you can pass to another method, like createTimer.
Part of the problem is no one has stepped up to write this sort of tutorial. The Beginner’s Tutorial is intended to be this but it’s incomplete.
Go down to the Timers section.
≥ createTimer(AbstractInstant instant, Procedure procedure): schedules a block of code to execute at a future time
instant is usually a DateTime calculated using the built in variable now.
≥ procedure is the block of code and is defined using lambda notation (i.e. square brackets)
Ok, it says it right there, the square brackets define a lambda.
Lambdas are a core party of the underlying language. You don’t expect a library to document how to write an if statement so we go to the base reference and find
As you might have guessed, a lambda expression is surrounded by square brackets (inspired from Smalltalk). Similarly to a method, a lambda …
This is the nature of ALL home automation systems. There are thousands of APIs out there. They are incompatible. They reach have their own quirks and requirements. They reach work in their own unique way. States like OH and NodeRed can only do so much to hide that complexity. If you want simple you need to stick to a commercial system that supports at most a handful of technologies.
Ok, the brackets define a lambda. A lambda is a method, i.e. a function, i.e. a block of code you can pass to another function. In this case you are defining a method to be called at a later time.
Since it’s a function you just list all the “commands” you want to execute like any other block of code. We usually treat the square brackets the same as curly brackets and indent the code to show context.
So your Timer would be:
createTimer(now.plusMinutes(1)) [ |
Since a lambda is a method, it can have arguments. The | separates the arguments from the code to be executed. Most of the time we do not use arguments with Timers because, as the reference says:
A lambda expression also captures the current scope. Any final local variables and all parameters that are visible at construction time can be referred to from within the lambda body.
This means in the way we use lambdas in createTimer we usually don’t need to pass anything to it because it already had copies of the local context. There is a way to create a timer with an argument but I’ve never used it and don’t recommend doing that so have forgotten how. There are examples on the forum though.