Hi,
I am having a potentially stupid question regarding blockly scripts.
For my blinds I have to check if the current time is before midday or after. I have installed the time extension.
However I cannot seem to find the correct blocks to get this easy operation done.
I already have a time item called midday which is derived from the astro binding but includes a date and not only a time. Can I just use this item or do I have to define a new item which includes just a time?
You’ll have to provide more information than this.
Put some logging blocks in to see what state your various Items and variables are, and logging blocks inside the If results so you can see where the code has gone. Then monitor the logs as you run the rule.
EDIT: I’ve now tested my blockly example from my first post: seems to work well.
EDIT: Looking at what you’ve got: you’re giving the comparison block the Item name, not the state of the Item. You will need to try with the Item state, and you may have to assign that state to a variable first.
now I seem to have a different problem. I am raeding through other posts as well and see the set varable to block a lot (the first one you used in your example) I however cannot find this block in my blockly. Does it come from a different library?
Your help is very appreciated. I am moving my whole smarthome from domoticz to openhab and while openhab has a lot going for it. The coding is quite different and the learning curve is rather steep especially knowing how i solved the problem before and not being able to replicate it.
Another small question. When I construct this script under the script section I cannot call for it from a rule. I always have to write a new script in every rule i create. is that correct? seems a bit strange.
No, you can call a rule from a rule. A Script as shown in MainUI is just a rule without any triggers or conditions and a single Script Action. It would probably be helpful for you to go through the Rules section of the Getting Started Tutorial (Rules - Introduction | v3 Documentation Preview) which is awaiting merge into the official docs.
But, usually the best approach in OH when you have a lot of rules that run the same code just on different Item events is to have just the one rule to handle them all instead of duplicating the same rule for each Item, even if those just call the same Script.
I would think that not needing to write any code at all would be simpler than needing to write code to handle this. That tutorial is thorough but it’s pretty simple.
Install the Alarm Clock rule template
Create DateTime Item(s) an populate them with the desired time from Astro, Android app’s next alarm, or whereever
Create a Script or Rule that will run at the time held by the Item(s) from 2 to do what ever it is you want, that tutorial changes the state of a TimeOfDay Item to drive a state machine. Other rules do tests like if (TimeOfDate.state == "DAY") instead of needing to break DateTimes apart and testing the hours, minutes, seconds individually.
Create a new rule and configure it using the Alarm Clock template
You never have to mess with code at all beyond coding what you want to have happen at that time.
I started to alter my rule starting from your example.
My problem now is that when I set a variable to an item coming from the astro binding the time and date is in a different format than the now coming from the datetime library.
I added two examples. The first one works.
The second one outputs an error which i guess is due to the different format.