Page 1 of 1

anyway to do a "Then"?

Posted: Thursday 04 May 2017 16:01
by gajotnt
I would like to have an event, so that when a switch turns off at a designated time interval it would turn off another switch.

example:
If switch1=on then switch1=off and time 23:00
set switch2=on

My biggest problem is finding a way that blocky knows when a switch is on then turns off. Maybe its really simple but im not seeing it.

Thanks

Re: anyway to do a "Then"?

Posted: Thursday 04 May 2017 16:16
by asjmcguire
You'd need to store the state in a user variable - because no programming language anywhere allows you to do that - the logic runs at the moment the state changes, if the state changes again - it will be evaluated in another copy of the same script. So instead you would need something a bit like:

if switch1==off and uservariable[prevSwitchState]==On and time > 23:00 and time < 07:00 then
switch2=on
elseif switch1==on then
set uservariable[prevswitchState]="On"
elseif switch1==off then
set uservariable[prevSwitchState]="Off"
end

Re: anyway to do a "Then"?

Posted: Thursday 04 May 2017 18:43
by gajotnt
ok will try that this weekend, thanks :D