Rule with Astro-binding does not trigger correctly

I use openhab version 3.4.3 (windows) and have implemented following rule:

configuration: {}
  - id: "2"
      cronExpression: "* 0/30 * * * ? *"
    type: timer.GenericCronTrigger
  - inputs: {}
    id: "6"
      itemName: Wetterstation_Dach_Aussentemperatur
      state: 25 °C
      operator: <
    type: core.ItemStateCondition
  - inputs: {}
    id: "3"
      itemName: AstronomischeSonnendaten_Set_Start
      state: START
      operator: <=
    type: core.ItemStateCondition
  - inputs: {}
    id: "5"
      itemName: AstronomischeSonnendaten_Noon_Start
      state: START
      operator: ">="
    type: core.ItemStateCondition
  - inputs: {}
    id: "1"
      considerConditions: true
        - efd0db9c9f
    type: core.RunRuleAction

This rule should trigger every 30min but only if:

  • temperature is < 25°C AND
  • time is in the afternoon (after noon AND before evening).

But the rule is never triggered so I assume my “but only” conditions are not correct. Can someone give me a hint what I am doing wrong? Is my state “START” correct and does it mean with the operator after that time?
The astro binding shows me the correct times.


No, START is not correct. :slight_smile:

First of all, I’m pretty sure that AstronomischeSonnendaten_Set_Start and AstronomischeSonnendaten_Noon_Start are of type DateTime. START, on the other hand, is an event triggered by an event channel.

I don’t know if it’s even possible to get the “DateTime compared to the current time” in the but-only-if part of a UI rule.

A simple approach would be to setup an Item which is set to different values through other rules, e.g. a Switch betweenMorningAndNoon which is set to ON and OFF from two rules which trigger via event channels. You could also use a String item TimeOfDay and use some rule to set it to “Night”, “Morning”, “Noon”, “Afternoon” and “Evening” or something similar and then test in this rule which string is set.

But of course it would be much simpler to add some lines of code to the rule code which is triggered :slight_smile:

You are right the AstronomischeSonnendaten_Set_Start is of type DateTime. I simply would like to trigger the rule when the current time is let’s say “greater” than the time from the astro binding.
When using the UI from the rule and WHEN case I can see following when choose the Item:


Question here:

  • Do I need to select “received a command” or “was updated” or “changed”?
  • What I put in “to State”?

or when choosing Trigger I see:


Question here:

  • I need to select “a trigger channel fired” or “status was updated” or " status changed"?
  • What I put in “Event”?

I think one of those two options should fullfill my needs for such a simple rule but I am not sure how I need to configure it.

Thanks in advance

Well, it depends :slight_smile:

The when-part of the rule is how it’s triggered.
If you want to have a trigger every 30 minutes, then use Time cron (but be aware that your first attempt is not “every 30 minutes”, but “once every thirty minutes for sixty seconds in a row”.

Time cron "* 0/30 * * * ? *"
           ^ ^ ^  ^ ^ ^ ^ ^
           | | |  | | | | |
           | | |  | | | | ---don't care about year (optional)
           | | |  | | | -----don't care about day of week 
           | | |  | | -------don't care about month 
           | | |  | ---------don't care about day 
           | | |  -----------don't care about hour 
           | | --------------repeat every 30th
           | ----------------start @ minute 0 
           ------------------don't care about second 

So “every 30 minutes” should look like "0 0/30 * * * ?"
You could set other values for both zeros to spread scheduled tasks, e.g. "5 3/30 * * * ?" would fire twice each hour at 03:05 and 33:05 (minute:second)
It’s very likely that you don’t want a cyclic rule at all though, :slight_smile: but that’s another story.

If you want a rule gets triggered via a command (that is, in the UI a button is pressed or a value is changed, and some specific channels are able to send a command as well), then use Item received command.
If you want to react on a changed value (for instance, the temperature has changed), then use Item changed trigger. If you want to get a rule running even if the Item only updated, then use Item received update.
The difference between update and changed: for instance, I have an interface to my door bell. Each time the bell button gets hit, the interface will send an ON to an Item. BUT it will never send an OFF when the button is released. So to react to the ON, I have to use received update (or I have to take care about resetting the Item, but why…)

There are many other triggers for rules, such as Channel events (please only use event channels, not the common ones) or even Thing updates

The But-Only-If is all conditions, what must be met to run the rule. BUT these are not dynamic (afaik), so you can’t use a state of an item as the state parameter (i.e. no firstitem.state > seconditem.state)

So, if you want a rule only triggered when it’s between sunrise and noon, you have to build an item which is of a certain state between sunrise and noon. The easiest way to do so is to build two rules which are triggered by channel astro:sun:local:rise#event and astro:sun:local:noon#event, the former will flip the item to ON, the latter will flip it back to OFF. Then you can use this new item in your first rule, together with the fixed temperature level.

Ok thanks for the reply. I do understand your solution as well as the cron timer better now. The only disadvantage is in my opinion when you need different astro bindings for several rules. Then you need to build always a “special” item for that which you can use afterwards. Of course this works, I can see that.

Therefore I (still) have the question about this:

When using the UI from the rule and WHEN case (see picture above) and use the “was updated” which “to state” could I use here and what would it mean? When I have such option with the UI and the astrobinding for sure it can be used - right?

And the same quesiton for the “Add Trigger”: When I use for example “status was updated” what I need to use for “Event”?


openHAB is event driven. There are different event types (see

for a complete list.
The point is: for Items there are three events:

  • Item received a command
  • Item status received an update
  • Item status has changed

The first will only trigger when a command is received, i.g. click in the UI or do a .sendCommand() in a rule
This is NOT about a status at all! It’s only a command!
The second trigger is, when the item received an update. It may differ from the previous status or not, the trigger will take place.
The third is triggered, if the update resulted in a change of the status. So, it’s on a specific part of the second trigger. Every changed event succeeds an update event.

On the other hand, there is only one option for an event channel, the event does occur. There is no command, there is no change (as the channels are stateless).

But there may be different events on one event channel, e.g. in astro you will get a START event and an END event for most if not all of the event channels. That is because of the definition of the events, e.g. sunrise is the moment, the sun goes up from negative elevation to positive elevation, so there is a imaginary line at the horizon (ignoring mountains, of course) and the sun passes this line, BUT: the sun isn’t a single dot but a circle, so there is a START (sun touches the line) and an END (sun leaves the line). Depending on Season and position the transition may take two to eight minutes (but I’m no expert to astronomy, so there may be even larger transition times).

If you want to use many different astro events, there is a Time of day rule for that purpose, see

AFAIR rlkoshak built the rule also in DSL and there may be a rule template already. The idea is, to build one String Item which then will be set to different Strings, maybe NIGHT, MORNING, NOON, AFTERNOON, EVENING, but you’re free to define it at your will. Then you can check whether the Item has one of a bunch of “allowed” statusses. It may be an option to use a Number Item instead so it would be possible to check ranges as well.

Yes, see Time Based State Machine [3.2.0;3.4.9] for OH 3.4 and Time Based State Machine [; for OH 4. Though you don’t really need to see those posts. You can go to Settings → Automation and find “Time Based State Machine” in the list, select it and add it. Be sure to read the readme and make sure you implement all the prerequisites first.

If you are OH 4 you will have to install openhab_rules_tools. That can be done through openhabian-config or by running the following command from your &OH_CONF/automation/js folder: npm install openhab_rules_tools.

I would like to install for OH4 your openhab_rules_tools. Could you please tell me how I do that on a windows machine?

Look for instructions for how to install npm on Windows. a once you have npm installed it’s the same command run from the automation/js folder: npm install openhab_rules_tools.

So far I have installed everything for OH4 right now. Although I read the instructions provided, I have somehow the impression it is not very easy to use for a beginner. Question: Is there maybe something like a step by step or video which I can use to get the idea how to implement it?

Thank you

Are you referring to OH in general or openhab_rules_tools? If the latter, no there are no videos. But you don’t really need them. All you would be doing is installing the library so the rule templates will work.

The steps are not that hard really.

  1. Install node.js and npm:
  2. open a command prompt, navigate to c:\<openhab_home>\conf\automation\js and issue the command npm install openhab_rules_tools
  3. in a browser open openHAB’s MainUI and navigate to Settings → Other Add-ons, select Time Based State Machine from the list of rule templates.
  4. Following the instructions in the Rule Template’s readme create a Group Item, String Item, and all the DateTime Items needed to represent all your times of day. Add the proper metadata to the DateTime Items.
  5. Navigate to Settings → Rules → +, select “Time Based State Machine” as the template and fill out the properties with the Items created in step 4.
  6. Manually run the rule by click the triangle play button and watch the log for errors. It checks the configuration of the rule and all the Items and generates meaningful errors if something is wrong.

Note, if you are on openHABian I think openhab_rules_tools gets installed by default. If not it can be installed from openhabian-config.

If you are looking for videos for openHAB in general, there are several in the openHAB Channel on YouTube and many others. However, you will not find a step-by-step tutorial that exactly addresses your specific use. OH is a platform with nearly an infinite set of possibilities. You will find lots tutorials, but almost none of them will be end-to-end except for Getting Started. You’ll have to chain tutorials together and combine them to get to your end goal.

Ok thank you. Up to step # 3 I managed without problems. But with the step#4 I struggle a bit (beginner). I created a new group item and the name " TimesOfDay". But I am not sure what I shall do iwth String Item, and all the DAteTime Itesms… as well as "Add the proper metadata to the DateTime Items.
Could you please give me some help or a short example on that point?

I am using OH4, windows machine. I also understand there is no video tutorial on each point, fair engouh.

Nothing. It just needs to exist. This is the Item that will hold the current time of day.

  1. Create a set of DateTime Items for each of your types of day. To make it easy, let’s just create one set for “default” days. If you have the times of day MORNING, DAY, EVENING, NIGHT you will need to create one DateTime Item for each of those (four total). You’ll need to populate them with the time that you want that time period to start (e.g. Astro, DateTime Picker Widget, from a rule, etc.).
  2. For each DateTime Item:
    • Navigate to Settings → Items → ItemName
    • click on Edit (pencil icon in upper right corner) → Parent Groups → Select the Group you created
    • click on “Add Metadata” then “add custom namespace”
    • enter a namespace (Note: this needs to be the same for all your DateTime Items)
    • populate the metadata. The “value” will be the String that gets sent to your String Item at the time of the DateTime Item’s state. The “config” depends on the type of the day. Since we are only working with default Items we use type: default. For example, the MORNING
value: MORNING
  type: default

When you create the rule from the template, you’ll select the Group, the String Item, and type in the metadata namespace. Once created, run the rule manually and watch the logs for errors.

Thanks for your answer - now I got it to work!! :smiley:

1 Like