Blockly programming driving me mad

Moderator: leecollings

Post Reply
shalafi
Posts: 4
Joined: Friday 02 December 2016 20:13
Target OS: Linux
Domoticz version:
Contact:

Blockly programming driving me mad

Post 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 2344 times
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Blockly programming driving me mad

Post 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
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
sion
Posts: 113
Joined: Friday 08 January 2016 12:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blockly programming driving me mad

Post 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?
running domoticz 3.4834 on rpi2, with
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.

Next: harmony hub.
dutchdevil83
Posts: 130
Joined: Monday 31 October 2016 19:34
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Netherlands
Contact:

Re: Blockly programming driving me mad

Post 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.
Hardware
1x Raspberry Pi
1x Razberry Z-Wave
1x RFXtrx433E
1x Toon
1x GoodWe Solarpanels
2x FGSD-002 Smoke Detector
1x FGBS-001 Binaire Sensor (RFID lezer)
7x FGMS-001 Motion Sensor
3x ZW089 Verzonken Deursensor
7x NC Wallplug
&lots of KaKu stuff
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Blockly programming driving me mad

Post 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.
shalafi
Posts: 4
Joined: Friday 02 December 2016 20:13
Target OS: Linux
Domoticz version:
Contact:

Re: Blockly programming driving me mad

Post 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
Slinkos
Posts: 81
Joined: Thursday 10 December 2015 0:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.4834
Location: Netherlands
Contact:

Re: Blockly programming driving me mad

Post 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"
sion
Posts: 113
Joined: Friday 08 January 2016 12:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blockly programming driving me mad

Post 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.
running domoticz 3.4834 on rpi2, with
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.

Next: harmony hub.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Blockly programming driving me mad

Post 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.
User avatar
StanHD
Posts: 347
Joined: Friday 12 July 2013 16:09
Target OS: Windows
Domoticz version:
Location: East Sussex, UK
Contact:

Re: Blockly programming driving me mad

Post 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.
Domoticz Main - Intel nuc, Windows, RFXTRX433E. Lan Relay Boards, Aeon Z-Stick Gen 5, Evohome HGI80, Milight WiFi, MySensors Ethernet Gateway, Harmony Hub
Python:- Broadlink RM2, Sonos
HA-Bridge - Amazon Echo / Alexa
shalafi
Posts: 4
Joined: Friday 02 December 2016 20:13
Target OS: Linux
Domoticz version:
Contact:

Re: Blockly programming driving me mad

Post by shalafi »

You keep mentioneing timers, what exactly do you mean with those?

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

/J
User avatar
StanHD
Posts: 347
Joined: Friday 12 July 2013 16:09
Target OS: Windows
Domoticz version:
Location: East Sussex, UK
Contact:

Re: Blockly programming driving me mad

Post 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.
Domoticz Main - Intel nuc, Windows, RFXTRX433E. Lan Relay Boards, Aeon Z-Stick Gen 5, Evohome HGI80, Milight WiFi, MySensors Ethernet Gateway, Harmony Hub
Python:- Broadlink RM2, Sonos
HA-Bridge - Amazon Echo / Alexa
sion
Posts: 113
Joined: Friday 08 January 2016 12:32
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Blockly programming driving me mad

Post 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).
running domoticz 3.4834 on rpi2, with
Hue bridge / bulbs.
lightwave rf sockets, mood controlers, sensors & contacts.
Home bridge / Siri.
Ha bridge / echo Alexa.
Hard wired alarm system - setting home / away status.

Next: harmony hub.
shalafi
Posts: 4
Joined: Friday 02 December 2016 20:13
Target OS: Linux
Domoticz version:
Contact:

Re: Blockly programming driving me mad

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest