Page 1 of 1
Automated on/off with block script help!
Posted: Saturday 04 February 2017 19:36
by colint
Hello all,
i have made a blocky script to automatically turn off my audio-rack when there is nothing playing with a delay of 1 hour, if you play music within the hour it will "reset" and nothing turns off. but now comes the problem.
I want to automatically turn on my audio-rack when some source of audio is being played.
i have made this but it is not working, i there somebody who can help me??
the part in the red line is the "auto on part".
switch "timer" is a switch with a off delay of 1 hour.
Re: Automated on/off with block script help!
Posted: Saturday 11 February 2017 11:08
by Spottyq
Hello,
It seems to me that the last two blocks are never executed. I don't use Blocky, but as a general rule in programming, an if-elseif-elseif statement ensures that **at most** one of the conditions is executed, the first that matches.
In your case, the condition you highlighted would never even get checked, since the if(audio in == open) statement before was true and has been executed.
I would recommend to add a second level of if-else :
Code: Select all
if (audio in == open)
if (audion-on == on and timer-var = not_triggered)
block 4
else
block 1
end
else
if (audio in == closed and timer == off and timer-var == truggered)
block 3
else
block 2
end
end
I hope this will help you.
Re: Automated on/off with block script help!
Posted: Saturday 11 February 2017 11:53
by Nautilus
Spottyq wrote:Hello,
It seems to me that the last two blocks are never executed. I don't use Blocky, but as a general rule in programming, an if-elseif-elseif statement ensures that **at most** one of the conditions is executed, the first that matches.
In your case, the condition you highlighted would never even get checked, since the if(audio in == open) statement before was true and has been executed.
I would recommend to add a second level of if-else :
Code: Select all
if (audio in == open)
if (audion-on == on and timer-var = not_triggered)
block 4
else
block 1
end
else
if (audio in == closed and timer == off and timer-var == truggered)
block 3
else
block 2
end
end
I hope this will help you.
It seems blockly (at least in Domoticz) is not something that follows all general programming rules

A couple of limitations that I'm aware of (relevant here): nested if's do not work; all "else if"'s are checked even when previous conditions match.
For OP's question, I'd maybe try with moving the non-working part to top. And also perhaps think some additional condition for "if 'audio in' = open" so that each if would only match one situation. The best option, though, would be to look into Lua...
