OH 3.2 Blockly Compare Times

Dear all,
i am currently trying to convert some of my rules to Blockly due to increased amount of blocks in OH 3.2 (big thank you for that by the way!!).
For the selection of scenes i am wondering if it is possible to compare the current time of the day to a fixed time and trigger the rule every minute? By doing so i dont need a rule for every scene with a specific time trigger.
Till now i only found the “now +0 seconds” block with i tried to put in a “if - do” with a “comparison”. However, i am not able to put anything into the “Comparison” block and also i dont know how this String(?) should look like. Is this even possible or is there an easier way? I installed the astro addon for blockly but there i can only select variable day events and no fixed times.
Thanky you!!

This smells of an XY Problem. If I understand you have a number of scenes that need to be triggered at a specific time. You want to write a rule that runs every minute and checks to see if it’s time to run a given scene.

In general, polling is not the best way to achieve anything. It would probably be better to use Timers.

However, in this specific use case, have you seen Creating Capabilities with Rule Templates: Time of Day ? There are rule templates that you can use to drive your time based scenes and you don’t even have to code anything to handle the timing, just set some DateTime Items.

If you have more complex needs (e.g. different times for different types of days) see Time Based State Machine . Again, all you need are some specially configured DateTime Items.

In answer to your question though, I don’t think time comparison blocks have been implemented yet.

No, they haven’t and I may be wrong but somehow deep in my head someone is telling we once talked about that and we were postponing maybe even because of new scripts that you have been working on :wink: … but I just can’t find it anymore in the forum…

Anyways, there are 3 ways:

  • we could implement some Standard blocks for the ZonedDateTime in the next release
  • the new inline script block could be used if it is accepted during the review
  • Someone could write a block library that just does that.

I like this idea. :smiley:

I was thinking the same but I’ve too many irons in the fire right now to do it myself (an issue on the AC to deal with the state description problem, some JS Scripting learning and writing, etc.). It would be a great first Blockly library for someone to tackle if they are interested in learning how.

Comparing DateTimes is something that needs to be done a lot in home automation so I suspect creating blocks will be needed at some point. It’s going to be a lot of blocks though. :-(. Maybe not so much if we just stick to comparisons and durations between and ignore the “getHour” type functions.

I was thinking the same. Even though the block library could fill this gap, it is such an important thing for standard blocks I would vote for a standard block implementation.

Thank you guys for your answers. So I understood that currently it’s not possible to compare times with blockly but its maybe something which will come. So I will stay tuned and cross my fingers :slight_smile:

I already started working on it: see Extending blockly by date comparison

1 Like

I’m also in the process to convert my rules to Blockly. I created a custom library which operates on ZonedDateTime.

Just copy the content of libraries/datetime/library.yml
In the main ui go to developer tools → block libraries → add a new library paste the content and save.

To set a time you need to alter the ZonedDateTime object.

The compare block compares two ZonedDateTimes. To compare two time values you have to set the dates of the objects to the same value.


Thanks for this David, right what I needed!

You guys rock!
Thank you a lot for your work. I will try it the coming days :slight_smile: