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


Question

Posted

Hi 

 

I'm trying to insert values in a variable

 

This Line 

 

Please login or register to see this code.

Gives this :-)

[08.11.2020] [11:13:44] [DEBUG] [SCENE116]: Christian tast {"439":2}

and this is what i need, but 

The 439 comes from the sourceTrigger.id

The 2 comes from sourceTrigger.value.keyId

 

How do I format the _mKeyId and afterwards fibaro.debug it so I can check its right?

 

Please login or register to see this code.

 

 

[08.11.2020] [11:32:17] [DEBUG] [SCENE116]: Christian tast {"439":2}

This line (fibaro.debug(tag,"Christian tast",_mKeyId);)gives 
[08.11.2020] [11:32:17] [DEBUG] [SCENE116]: Christian tast table: 0xffff380794f0

 
how do I change it to {"439":2}?
 

2 answers to this question

Recommended Posts

  • 0
Posted (edited)
15 minutes ago, ChristianSogaard said:

Hi 

I'm trying to insert values in a variable

 

Please login or register to see this code.

[08.11.2020] [11:32:17] [DEBUG] [SCENE116]: Christian tast {"439":2}

This line (fibaro.debug(tag,"Christian tast",_mKeyId);)gives 
[08.11.2020] [11:32:17] [DEBUG] [SCENE116]: Christian tast table: 0xffff380794f0

 
how do I change it to {"439":2}?
 

 

 

Please login or register to see this code.

Reason being that {[439]=2} becomes a "sparse table", a 2 at position 439 and that is not valid for the json converter.

Converting 439 to the string "439" makes it a simple key-value table that can be converted.

Edited by jgab
  • Like 1
  • 0
  • Inquirer
  • Posted (edited)
    Thank you @jgab
    Thank worked - so next I am trying to do some simple math
     
    So sourceTrigger.id  = 439 and sourceTrigger.value.keyId =2 
     
    I want to do 439+1+(2*2) = 440 
    mld = 440 
     
    mId = tostring(math.abs((tonumber(sourceTrigger.id) + 1 + 2 * tonumber(sourceTrigger.value.keyId))));
    LINE 24 fibaro.debug(_tag, "Led""id =" .. mId);
     
    I get [ERROR] [SCENE116]: (load):24: Assertion failed: Expected string
     
    This is my goal
    local _matrixLedIds = {}
    mId = tostring(sourceTrigger.id) + 1 + 2 * sourceTrigger.value.keyId);
    fibaro.debug(_tag, "matrixLed""id =" .. mId);
    table.insert(_matrixLedIds,mId);
     
    I made it a string ??
    Edited by ChristianSogaard

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