Page 1 of 1
and/if with times
Posted: Thursday 02 April 2020 7:47
by desertdog
I tried to write this blockly script where my curtain will open every morning at sunrise, except when the sunrise is before 7:00. In that case they open at 7:00.
Unfortunately, this gives the following error, so it seems you can not compare time like this:
2020-04-02 07:35:00.216 Error: EventSystem: Lua script error (Blockly), Name: Curtains_2 => [string "result = 0; weekday = os.date('*t')['wday']; ..."]:1: ')' expected near 'comparevariable'
Is there any way to make this work?
Re: and/if with times
Posted: Thursday 02 April 2020 8:14
by Ernstl
You Need a Time-Pice (Blue) After the „and“ in the else if line, Not a logic pice (Green).
Re: and/if with times
Posted: Thursday 02 April 2020 8:34
by desertdog
Ernstl wrote: ↑Thursday 02 April 2020 8:14
You Need a Time-Pice (Blue) After the „and“ in the else if line, Not a logic pice (Green).
You mean the "Sunrise < 07:00" part, right? The problem is that there is no time-piece to do this.
Re: and/if with times
Posted: Thursday 02 April 2020 10:37
by Ernstl
Okay, you´re right.
I Think it is not possible to compare to time-points.
Just try:
else if Time=07:00 and Time>=Sunrise
Re: and/if with times
Posted: Thursday 02 April 2020 13:27
by Thuis
Hello i am only trying to help, i have done it like this :
Strange one must think it would be a time between AND another time. But with OR it seems to work.
Re: and/if with times
Posted: Thursday 02 April 2020 13:58
by desertdog
Thuis wrote: ↑Thursday 02 April 2020 13:27
Hello i am only trying to help, i have done it like this :
Strange one must think it would be a time between AND another time. But with OR it seems to work.
Since time is only within one day
should work the same
Re: and/if with times
Posted: Thursday 02 April 2020 13:58
by desertdog
Ernstl wrote: ↑Thursday 02 April 2020 10:37
Okay, you´re right.
I Think it is not possible to compare to time-points.
Just try:
else if Time=07:00 and Time>=Sunrise
Yes works!
Re: and/if with times
Posted: Thursday 02 April 2020 17:54
by AllesVanZelf
Why not just:
If [Time] => 7:00 AND [Time] >= [Sunrise]
Do [Curtains] = [Open]
Personally I would limit the time to let say 10:00 to prevent opening off the curtains in the evening.
If [Time] => 7:00 AND [Time] >= [Sunrise] AND [Time] =< 10:00
Do [Curtains] = [Open]
Re: and/if with times
Posted: Thursday 02 April 2020 18:54
by Thuis
Just use OR instead of AND is my finding
between 6:00 or 7:00 not between 6:00 and 7:00 for blockly.
Otherwise it only works on 6:00 and on 7:00 not at 6:01 until 6:59.
Or you want to open the curtains only when sunrise matches the time of 7:00
but that is just me.
Re: and/if with times
Posted: Thursday 02 April 2020 19:04
by desertdog
Thuis wrote: ↑Thursday 02 April 2020 18:54
Just use OR instead of AND is my finding
between 6:00 or 7:00 not between 6:00 and 7:00 for blockly.
Otherwise it only works on 6:00 and on 7:00 not at 6:01 until 6:59.
Or you want to open the curtains only when sunrise matches the time of 7:00
but that is just me.
There are two lines, the first one:
time = sunrise AND time > 07:00: so that will open the curtain when the sunrise is after 7:00, eg: 7:01, 7:45, etc
second one:
time = 07:00 AND time >= sunrise: will open the curtains at 07:00 when the sunrise is before 07:00
Re: and/if with times
Posted: Thursday 02 April 2020 19:40
by Thuis
That is good Thanks
Re: and/if with times
Posted: Thursday 02 April 2020 20:00
by AllesVanZelf
desertdog wrote: ↑Thursday 02 April 2020 19:04
There are two lines, the first one:
time = sunrise AND time > 07:00: so that will open the curtain when the sunrise is after 7:00, eg: 7:01, 7:45, etc
second one:
time = 07:00 AND time >= sunrise: will open the curtains at 07:00 when the sunrise is before 07:00
You are complicationg things. Please have a look at my post above. It will work in just one line.
Re: and/if with times
Posted: Thursday 02 April 2020 20:29
by desertdog
Your line works but will keep triggering the whole day. If I decide to close the curtains somewhere during the day they will open again since it > 07:00
Re: and/if with times
Posted: Thursday 02 April 2020 20:44
by AllesVanZelf
desertdog wrote: ↑Thursday 02 April 2020 20:29
Your line works but will keep triggering the whole day. If I decide to close the curtains somewhere during the day they will open again since it > 07:00
If you add this: AND [Time] =< 10:00
How would it be possible that it is triggered all day? I do not understand that.
Re: and/if with times
Posted: Thursday 02 April 2020 20:58
by desertdog
It still opens my curtains again when I decide to watch tv with close curtains at 9:30.
Re: and/if with times
Posted: Friday 03 April 2020 9:55
by AllesVanZelf
That is what you want isn't it? 9:30 is later then 7:00. Maybe we are missing some information. Is this tv part of the script like the script of Thuis?
Re: and/if with times
Posted: Friday 03 April 2020 10:36
by desertdog
No, I want to open the curtain when it's sunset, if the sunset is 7:00 or later.
If the sunset is earlier than 7:00, the curtains have top open at 7:00.
So say the sunrise was at 6:43 and the curtains have opened at 7:00 as programmed. If for whatever reason (sunlight on my tv, too bright for my hangover, vacuuming the curtains) I decide to close the curtains again at 7:15, I don't want a script to re-open it immediately.
There is another reason I only want the script to open at only 1 specific time, being 7:00 or sunrise. This means in case of an error there is a maximum of two triggers instead of every minute until that between the time you suggest. The curtains are controlled by a motor that doesn't give feedback but stops when there is too much resistance. If for some reason this script keeps firing every minute opening the curtains while already open, it might lose the resistance and keeps on opening. which may lead to overheating