Page 1 of 1

Blockly programming driving me mad

Posted: Friday 02 December 2016 20:26
by shalafi
This blockly event is driving me mad. It's supposed to turn lights on in the morning and evening, and turn them off in between and during night. Differnt times week vs. weekend.

If i activate this all lights turn off and if i manually turns everything on everything turns off again after a short while. Can anyone see any galring mistake I've made... i guessit could be done smarter but this should work (in my head at least).

A quite tall image in this link
https://bertholdsson.com/weekly_schedule.jpg
Same image as in the link above
Same image as in the link above
weekly_schedule.jpg (122.14 KiB) Viewed 2350 times

Re: Blockly programming driving me mad

Posted: Friday 02 December 2016 20:36
by Derik
perhaps do a check in the firstrow.. after or before time
If x = on the y off
Or if x off then z on

Re: Blockly programming driving me mad

Posted: Saturday 03 December 2016 1:35
by sion
I may be missing something, but would it not be easier to put all the lights in a group, and then set timers on that group?

Re: Blockly programming driving me mad

Posted: Saturday 03 December 2016 11:54
by dutchdevil83
sion wrote:I may be missing something, but would it not be easier to put all the lights in a group, and then set timers on that group?
+1 was going to say the same thing! Please use groups and timers for this. Will save you lots of time when adding or removing switches later on.

Re: Blockly programming driving me mad

Posted: Saturday 03 December 2016 12:17
by Egregius
Or start scripting, would be much better for stuff like this.
Like check every lights status before sending command instead of just sending commands to all lights.

Re: Blockly programming driving me mad

Posted: Saturday 03 December 2016 15:52
by shalafi
Thank you all. i tried your ideas and grouping made it all much more readable but I think I'll go with the scripting path. As i understand i can use Python and that should make it more easy to program .



Thanks
Jörgen

Re: Blockly programming driving me mad

Posted: Saturday 03 December 2016 16:10
by Slinkos
What I found is, that it's not a good idea to put only days of the week in your if statement, because it makes your event execute every minute, because the if statement is true every time. It's better to make a switch called "Weekday" and a switch called "Weekend" or something. And put a timer on those switches. Then change your blocky to "If weekday = on" or "If weekend = on"

Re: Blockly programming driving me mad

Posted: Sunday 04 December 2016 0:35
by sion
Slinkos wrote:What I found is, that it's not a good idea to put only days of the week in your if statement, because it makes your event execute every minute, because the if statement is true every time. It's better to make a switch called "Weekday" and a switch called "Weekend" or something. And put a timer on those switches. Then change your blocky to "If weekday = on" or "If weekend = on"
You could use one switch, if it's on it's the week, or if it's off it's the weekend. However, as it will always be either one or the other - Will the script not still run every min to check the times?

Either way will work I guess, but Is there any advantage to using a script rather than a timed group for this? Or just preference.

Re: Blockly programming driving me mad

Posted: Sunday 04 December 2016 6:10
by Egregius
Why use switches for time related stuff? You know that every added switch requires a little bit extra effort of Domoticz?

Code: Select all

if(in_array(date('N'),array(1,2,3,4,5))) //Weekday
if(in_array(date('N'),array(6,7))) //Weekend
 
If you can base64 decode and json decode in Python maybe my pass2php script can be used.
It passes the lua tables devicechanged, otherdevices, otherdevices_idx and otherdevices_lastupdate to a php page. Could be any language there.

Re: Blockly programming driving me mad

Posted: Sunday 04 December 2016 10:29
by StanHD
Just going back to the Blockley. Use the timers method and groups and remove the "nested" "If" structure. Now that it is much simplified use "else if" to rebuild. Then I am sure it should work. I have never managed to successfully get a nested "if" structure to work.

Re: Blockly programming driving me mad

Posted: Thursday 08 December 2016 19:49
by shalafi
You keep mentioneing timers, what exactly do you mean with those?

Sorry, but i don't really understan :-/

/J

Re: Blockly programming driving me mad

Posted: Thursday 08 December 2016 20:06
by StanHD
If you go into the "Timer" function on a standard switch, you will be able to build a schedule there. Then use the switch state in a script or Blockly as part of an "if" condition.
I use several "Dummy" switches as timers.

Re: Blockly programming driving me mad

Posted: Thursday 08 December 2016 20:33
by sion
shalafi wrote:You keep mentioneing timers, what exactly do you mean with those?

Sorry, but i don't really understan :-/

/J
create a group from the domoticz web interface on the groups / scene page. ( make sure it's a group as you want to turn them off too).
Add all your lights to this group.

Then on the main page, you will now see the group switch. Under this is a timer button. Next to the log button etc...
click on timer, and it will take you to a schedule page where you can set as many on and off times as you like.
Including specific to the day of the week.

I like the group method. It's easy to add a light to the group later on, and the original timers still stand.
I use something similar - I have all the light turn off in order at the end of the night If we are not home, to simulate some one going around the house "locking up".
You can do this with off delays in the group. ( you wouldn't want this for normal functionality).

Re: Blockly programming driving me mad

Posted: Thursday 08 December 2016 21:05
by shalafi
Wow, this was neat. I had already a couple of groups and putting them on timer was exactly what i needed. Much easier than dragging blocks of blockly for this kind of simple repetive tasks.

Thanks

/J