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!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

[LUA] Stripping Table content in usable values


Question

Posted

Hi,

Maybe someone can help me to figure out this one.

I have a table with tis content:

Please login or register to see this code.

What I'm trying to do?

I want to strip the tablecontents so that the b-values represents levels with, in this case, icon-id's, sorted from the highest level to the lowest level.

It should be flexible to add more values in the table without worrying where to put it (i.e. if put b98 = 1067 to the top the ouput should be automatically be organized.

The output from the top table should be:

Values b:

if between 95 and 100 percent then iconnumber 1068

if between 50 and 100 percent then iconnumber 1069

if between 30 and 50 percent then iconnumber 1070

if between 5 and 30 percent then icon number 1071

When the a insetion is made in the tail of the table 'b98 = 1067' then the result should be:

if between 98 and 100 percent then iconnumber 1067

if between 95 and 98 percent then iconnumber 1068

if between 50 and 100 percent then iconnumber 1069

if between 30 and 50 percent then iconnumber 1070

if between 5 and 30 percent then icon number 1071

Is there a smart way to do this?

2 answers to this question

Recommended Posts

  • 0
Posted

function getIcon(watt)

if(watt > 8000) then return 1049

elseif(watt >= 7500) then return 1047

elseif(watt >= 6500) then return 1046

elseif(watt >= 5500) then return 1045

elseif(watt >= 4850) then return 1044

elseif(watt >= 4250) then return 1043

elseif(watt >= 3750) then return 1042

elseif(watt >= 3450) then return 1041

elseif(watt >= 3350) then return 1040

elseif(watt >= 3250) then return 1039

elseif(watt >= 3150) then return 1038

elseif(watt >= 3050) then return 1037

elseif(watt >= 2950) then return 1036

elseif(watt >= 2850) then return 1035

elseif(watt >= 2750) then return 1034

elseif(watt >= 2650) then return 1033

elseif(watt >= 2550) then return 1032

elseif(watt >= 2450) then return 1031

elseif(watt >= 2350) then return 1030

elseif(watt >= 2250) then return 1029

elseif(watt >= 2150) then return 1028

elseif(watt >= 2050) then return 1027

elseif(watt >= 1950) then return 1026

elseif(watt >= 1850) then return 1025

elseif(watt >= 1750) then return 1024

elseif(watt >= 1650) then return 1023

elseif(watt >= 1550) then return 1022

elseif(watt >= 1450) then return 1021

elseif(watt >= 1350) then return 1020

elseif(watt >= 1250) then return 1019

elseif(watt >= 1150) then return 1018

elseif(watt >= 1050) then return 1017

elseif(watt >= 950) then return 1016

elseif(watt >= 850) then return 1015

elseif(watt >= 750) then return 1014

elseif(watt >= 650) then return 1013

elseif(watt >= 550) then return 1012

elseif(watt >= 450) then return 1011

else return 1011 end

end

thats from a power consumption virtual device i use does that help you? it is not my code mind you!

  • 0
  • Inquirer
  • Posted

    Thanx for responding but that is not quite what I'm looking for, although the code is basically doing what I'm trying to achieve, but it is to static

    the getIcon(watt) and return values should be more dynamic, depending on the table-contents.

    [ Added: 2014-09-27, 12:58 ]

    Anyone?

    Join the conversation

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

    Guest
    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...