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

Assertion failed: Expected function


Question

Posted

When I'm trying to run this code

Please login or register to see this code.

I'm getting this error:

Please login or register to see this code.

Could someone help me here?

8 answers to this question

Recommended Posts

  • 1
Posted (edited)

Maybe try following timeout:

 

Please login or register to see this code.

 

Please login or register to see this link.

 

Edited by jakub.jezek
Coma removed behind function()
  • 1
Posted

Remove the extra () in SetTimeout, like this

 

Please login or register to see this code.

  • 0
  • Inquirer
  • Posted

    Please login or register to see this code.

    That's really strange way of using anonymous function ? I can confirm that both ways are working. I'd go with `fibaro.setTimeout(10000, went)` as it is a little bit more readable. 

    • 0
    Posted
    2 minutes ago, wnowicki said:

    That's really strange way of using anonymous function ?

    I see you use the correct terminology here... "anonymous function". Because of that, I am assuming you might be interested in a little background. Here is a little Lua secret: Lua does not have named functions, all functions are anonymous!

     

    Sounds weird? It probably sounds as if I am wrong because you write it like this...

    Please login or register to see this code.

    ...that sounds like you created a function with name "went" - does it not? No, it does not, because that is syntactic sugar for defining a variable and storing an anonymous function in it. You can write it like this:

     

    Please login or register to see this code.

    That is effectively the same. So when you call fibaro.setTimeout(10000, went) you are actually passing the contents of variable "went" and after 10 seconds setTimout will "call that function with no arguments". Adding () to went like this setTimeout(10000, went()) would not pass a function to setTimout, it would call function in "went" and pass the result of that call as 2nd argument- which in your case is not a function because "went()" does not return anything. That is why the error in your original post is "Assertion failed: Expected function".

     

    When you do "fibaro.getValue(...)" you are calling an anonymous function, stored in field "getValue" of table "fibaro". Again, the function is anonymous, but we c an call it because it was stored somewhere...

    • 0
  • Inquirer
  • Posted

    @petergebruers thanks for that explanation, right we want to pass a reference as an argument and it would be called later on inside `setTimeout()`

    • 0
    Posted

    @petergebruers explains the "secret" behind named functions :-) 

    Here is even more details about the different syntaxes you can stumble on

     

     

    The reason for using a anonymous function for ex. setTimeout, and why it's common to see that in code,  is if you need to pass arguments to the function

    Please login or register to see this code.

     

     

    • 0
    Posted

    Hi

    I have this code , I check the opening sensor and I gave his state to global variable wamessage .... and with  hub.callUI I would like to send to me trought whatsapp message

     

    local door = fibaro. get (391"value"
        if (door) then  
        print (hub.getName(391).. " opened"
        local message = hub.getName(391) .. " opened"
        fibaro.setGlobalVariable(wamessage, message) 
        hub.callUI(513'onReleased''button6_1')
        else 
     
    And for the following line fibaro.setGlobalVariable(...)  I get this error: "Assertion failed: Expected string"
     
    Can you help me?
    • 0
    Posted
    19 hours ago, iTibor said:

    Hi

    I have this code , I check the opening sensor and I gave his state to global variable wamessage .... and with  hub.callUI I would like to send to me trought whatsapp message

     

    local door = fibaro. get (391"value"
        if (door) then  
        print (hub.getName(391).. " opened"
        local message = hub.getName(391) .. " opened"
        fibaro.setGlobalVariable(wamessage, message) 
        hub.callUI(513'onReleased''button6_1')
        else 
     
    And for the following line fibaro.setGlobalVariable(...)  I get this error: "Assertion failed: Expected string"
     
    Can you help me?

     Update>

     

    The correct and working syntax is:

    fibaro.setGlobalVariable("wamessage", message) 

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