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.
Use Date block shown below but I cannot connect it to the Math block.
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
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.
A short feedback from my side and for the other readers.
Substracting dates.
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.
“get contextual attribute”
Thanks, this is working well. I mixed up “contextual info” and “get context attribute”
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.