How to calculate minutes since midnight in Blocky (date block, read paramater)

Hi all,

i want to adjust an old javascript in my system but also want to migrate it to Blocky.
It looks already quite fine but the script requires the minutes after midnight (as many scripts do).

What i already tried.

  1. Use Date block shown below but I cannot connect it to the Math block.

  2. Next Idea was to have a script that handover a parameter to the script.
    Here I just have the issue that I do not know how to read that parameter in Blocky

  3. The last resort would be to create a proxy item that holds the minutes since midnight.
    To be honest I want to avoid this because afaik every item gets persisted.

Thanks for your support here, happy holidays!
BR
/Franz

“Text of” is going to give you a String. You can’t do math with a String. But you should be able to create a new variable and set that date block to the variable and then use the variable in the math block.

I think that’s done through the “get contextual attribute” block.

You can change that by defining a .persist file and only list those Items you want to have persisted.

and the right part …

Do not remove the " x 1 " (typecast to number).

Hi Rich,

A short feedback from my side and for the other readers.

  1. Substracting dates.
    image
    This does not work even without parsing.
    Seems to be logical somehow to me because the Zoned Date Time Object is to complex for such simple operations.

  2. “get contextual attribute”
    Thanks, this is working well. I mixed up “contextual info” and “get context attribute”

  3. Persistence File
    Woooohooo seems to be quite complex but overall an issue that i need to analyze in detail

Thanks for the feedback Rich!

BR
/Franz

Hi @anon71759204,

yes i also thought about a similar situation as I wake up this morning.
I’ll give it a try and show my Version lateron.

BR
/Franz

Hi @anon71759204,

thanks again for the example.
The typecast things are always a bit strange to me (I’m coming from c#).

I wish you nice holidays!

that was in my mind this morning:

That wouldn’t work even in code as written and I’m pretty sure addition and substraction of ZonedDateTimes is not supported in Blockly. In Rules DSL et. al. you would use the Duration class.

var diff = java.time.Duration.between(now, midnight)

Doing math like that has never been supported with ZonedDateTimes.

That’s going to be the case for any and all things in openHAB or any other such system as openHAB. OH provides a decent default behavior which works for most users in most cases. However, once you need to override the default it’s going to be complex because the overrides need to support everyone’s use cases.

It might make more sense when you realize that you are seeing a graphical representation of JavaScript code which is running on and interacting with Java Objects and Classes. It’s an exceptionally complex type environment.

1 Like