Page 1 of 1
If Then not working in Blockly?
Posted: Friday 12 August 2016 19:37
by Noudje
I have created the following blockly script:

- Knipsel.PNG (31.97 KiB) Viewed 1338 times
but in the log file, I find:
2016-08-12 19:35:00.517 Start
2016-08-12 19:35:00.517 195
2016-08-12 19:35:00.517 Light on
2016-08-12 19:35:00.517 Light off
Why is the If/Then not working?
Re: If Then not working in Blockly?
Posted: Friday 12 August 2016 20:36
by tozzke
as far as I know you can't use an If-block inside another If-block. You can only use an If-block and then multiple Else if-blocks
So what you should do is something like:
Code: Select all
If [Time > 07:00] and [Time <= 23:45]
Do [Write to log "Start"]
[Write to log M-R Motion Sensor 1 - Lux actual]
Else if [Time > 07:00] and [Time <= 23:45] and [M-R Motion Sensor 1 - Lux actual <= 30]
Do [Write log "Light on"]
Else if [Time > 07:00] and [Time <= 23:45] and [M-R Motion Sensor 1 - Lux actual > 30]
Do [Write to log "Light off"]
Else if [Time < 07:00] or [Time > 23:45]
Do [Write to log "Lamp altijd uit"]
Except I don't know if you really want to add the first and last If-statements because this is going to trigger very often. You could change that by adding a variable 'Already_started?' with value 1/0 (Integer) or yes/no (String) so you'll get something like this:
Code: Select all
If [Time > 07:00] and [Time <= 23:45] and [Var A-F Already_started? = "no"]
Do [Set Var A-F Already_started? = "yes"]
[Write to log "Start"]
[Write to log M-R Motion Sensor 1 - Lux actual]
Else if [Time > 07:00] and [Time <= 23:45] and [M-R Motion Sensor 1 - Lux actual <= 30]
Do [Write log "Light on"]
Else if [Time > 07:00] and [Time <= 23:45] and [M-R Motion Sensor 1 - Lux actual > 30]
Do [Write to log "Light off"]
Else if [Time < 07:00] or [Time > 23:45] and [Var A-F Already_started? = "yes"]
Do [Set Var A-F Already_started? = "no"]
[Write to log "Lamp altijd uit"]
Now the first and last statement will only trigger once between those times
Re: If Then not working in Blockly?
Posted: Saturday 13 August 2016 19:54
by Noudje
Thnx tozzke! That is the solution. Weird that I can not use nested if-blocks?