Page 1 of 1

Help with Else If logic

Posted: Tuesday 07 March 2017 11:32
by gavacac
I'm having a problem with one of my blocky events. I suspect I've got a fundamental misunderstanding of the way it works. Maybe someone can help me?

Essentially, I want some logic as follows:

If SwitchA = 1 and SwitchB = 1, set SwitchB to 2.
Else if Switch A = 1 and Switch B =2, set SwitchB to 3.

I have implemented this in Blocky but if I then set Switch A to 1 and Switch B to 1, Switch B changes to 3 whereas I would expect it to be 2.

From the log, I can see that what is happening is that the first part is running (and Switch B is set to 2) and then the event is immediately triggered again and this time the second part is applied and Switch B is set to 3.

Can anyone give me any tips?

Re: Help with Else If logic

Posted: Tuesday 07 March 2017 11:35
by sisaenkov
This works as expected. All is correct and meets the conditions.
What do you want to do?

Re: Help with Else If logic

Posted: Tuesday 07 March 2017 11:41
by gavacac
Without going into loads of detail, when Switch A is set to 1 for the first time, I want to set Switch B to 2. When Switch A is set to 1 for the second time, I want to set Switch B to 3.

Re: Help with Else If logic

Posted: Tuesday 07 March 2017 11:46
by emme
you want a toggle button.....

try this:

Code: Select all

If SwitchA = 1 then
   If SwitchB = 2 then
      SwitchB = 0
      SwitchC = 3
   else
      SwitchB = 2
      SwitchC = 0
the first block is a simple IF
the inner block is a IF/else block
(they are different ;) )

Re: Help with Else If logic

Posted: Tuesday 07 March 2017 11:52
by sisaenkov
Also you can use a variable.

If SwitchA == 1 and SwitchB == 1 and Var == 0 then
SwitchA = 0
SwitchB = 2
Var = 1
elseif SwitchA == 1 and SwitchB == 2 and Var == 1 then
SwitchA = 0
SwitchB = 3
Var = 1

It's all depends on your detailed conditions.

Re: Help with Else If logic

Posted: Thursday 09 March 2017 7:29
by jannl
I think blockly is the problem in this case, try with lua.

Re: Help with Else If logic

Posted: Thursday 09 March 2017 10:41
by gavacac
I managed to get it to work with a variable. Thanks for the suggestions.

Re: Help with Else If logic

Posted: Sunday 26 March 2017 12:18
by Spitfire
Domoticz blocky 'else if' handling is broken. Nothing should be run after a condition has been true.