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

make small table with two values for each record


Question

Posted

HC3

I would like to store a small table in global variable with a list of songname and the length in time of each song,  so can make a table which has the songs as a list, however i would like to also store alongside each song name the time it takes to play, can anyone please guide me on how to construct this table?  Thank you ever so much.

8 answers to this question

Recommended Posts

  • 0
Posted

If each song name is unique and used as table key

Please login or register to see this code.

 

Song titles are not unique and we only create an array of song records

Please login or register to see this code.

 

  • 0
  • Inquirer
  • Posted
    On 11/21/2021 at 4:46 PM, jgab said:

    Please login or register to see this code.

    I wanted to give each song a number as in S1, title,length, so would i just need to add this on each line?

    {number = 'S1',Name = SongName,length = 4*60}

    and then to retrieve the details of S1, print(song.number) or print (song.Name etc...?

    • 0
  • Inquirer
  • Posted

    also in your return what is the ,"s" doing?

    • 0
    Posted

    s = seconds :)

     

    • 0
  • Inquirer
  • Posted

    thank you @jgab

    is it possible to have more then just the title and value in a table, what i would like is, songnumber,title,length.

    how would write such a table and how would i get back the values?

    • 0
    Posted

    Here is example:

     

    Please login or register to see this code.

     

     

    • 0
  • Inquirer
  • Posted
    On 12/22/2021 at 8:02 PM, petrkl12 said:

    Here is example:

     

    Please login or register to see this code.

    thank you,

    when i run this in scene if it is a basic table ie with just title and name i run this to get the value

    local jMT = json.decode(fibaro.getGlobalVariable("jMusicTable"))
    fibaro.debug("Scene47", "Play "..jMT.Song.S1)

    how do i reference the song name from your table example?

     

    On 12/22/2021 at 8:02 PM, petrkl12 said:

     

     

    • 0
    Posted
    1 hour ago, Jay Ess said:

    thank you,

    when i run this in scene if it is a basic table ie with just title and name i run this to get the value

    local jMT = json.decode(fibaro.getGlobalVariable("jMusicTable"))
    fibaro.debug("Scene47", "Play "..jMT.Song.S1)

    how do i reference the song name from your table example?

    you can do it also this because it is array.

    songs2[1].title

    songs2[1].songTitle

    songs2[2].title

    songs2[2].songTitle

    songs2[3].title

    songs2[3].songNumber

    etc.

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