Automated on/off with block script help!

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
colint
Posts: 12
Joined: Friday 25 November 2016 13:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Automated on/off with block script help!

Post 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.
Attachments
blocky script
blocky script
Schermafbeelding 2017-02-04 om 19.23.12.png (100.85 KiB) Viewed 761 times
Spottyq
Posts: 3
Joined: Saturday 11 February 2017 10:56
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: ::1
Contact:

Re: Automated on/off with block script help!

Post 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.
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: Automated on/off with block script help!

Post 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...:)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest