Help with Else If logic

Moderator: leecollings

Post Reply
gavacac
Posts: 12
Joined: Tuesday 06 December 2016 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Help with Else If logic

Post 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?
User avatar
sisaenkov
Posts: 50
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: Help with Else If logic

Post by sisaenkov »

This works as expected. All is correct and meets the conditions.
What do you want to do?
gavacac
Posts: 12
Joined: Tuesday 06 December 2016 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Help with Else If logic

Post 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.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Help with Else If logic

Post 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 ;) )
The most dangerous phrase in any language is:
"We always done this way"
User avatar
sisaenkov
Posts: 50
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: Help with Else If logic

Post 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.
jannl
Posts: 625
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: Geleen
Contact:

Re: Help with Else If logic

Post by jannl »

I think blockly is the problem in this case, try with lua.
gavacac
Posts: 12
Joined: Tuesday 06 December 2016 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Help with Else If logic

Post by gavacac »

I managed to get it to work with a variable. Thanks for the suggestions.
Spitfire
Posts: 20
Joined: Thursday 29 December 2016 9:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Help with Else If logic

Post by Spitfire »

Domoticz blocky 'else if' handling is broken. Nothing should be run after a condition has been true.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests