Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,


as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.


As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!



Smart Home Forum by FIBARO Team

  • 0

Switch-case possible as substitution for many if-statements?




I have a LUA programming question  - for making a scene that helps HC2 heat panel control my AC via ZXT-120.


My end-goal (for now) is to set the Fan speed and AC mode (heat/cool/off) by the logic in the following table (explanation below)


Please login or register to see this image.

/monthly_2019_05/Capture.PNG.7e677408221735d0f02545c29668d97f.PNG" />


Explanation for table:
Setpoint is retrieved from Heat Panel. The deviation from setpoint is calculated from a global temp-variable subtracting setpoint to get the deviation. Based on that daviation AND the outside temperature, the AC will be set do fan speed and mode.


I realize that the amount of if statements would be too big for me to handle, so someone suggested to use "switch-case" (which i am not familiar with but is sort of understood). The below example was provided for me:



// High = 1, Medium= 2.......

//inde case

Array_Of_Temp_Offsets = INT[20]
Array_Of_Temp_Offsets[0]= -1.5
Array_Of_Temp_Offsets[0]= -1.0

//in your case
Active_Setpoint_Deviation_Array_Pos = 0
FOR j = 0 To Array_Of_Temp_Offsets size DO 
IF Array_Of_Temp_Offsets[j] +setpunt < tmp 
Active_Setpoint_Deviation_Array_Pos = Active_Setpoint_Deviation_Array_Pos + 1

Active_Setpoint_Deviation_Array_Pos = Active_Setpoint_Deviation_Array_Pos + 1

AC-setpoint = Fanstate[Active_Setpoint_Deviation_Array_Pos]


The problem is i still can't translate this to anything sensible in LUA.


Can anyone please help me?





Edited by mainnsto
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...