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

Very simple HC3 LuA scene doesn't work correct


Question

Posted

Hello,

 

I have create a very simple LUA scene, but this doesn't work reliable:

Condition/Trigger:

{
  conditions = { {
      isTrigger = true,
      operator = "<",
      property = "Einspeisung",
      type = "global-variable",
      value = "-300"
    } },
  operator = "all"
}

Action:

hub.call(274, 'turnOn')

 

So here is a global variable "Einspeisung" which changes its value every 5 minutes, if the value less then -300 then trigger a device on.

But trigger will be fired when the value change from + to - the value does not matter then.

I try also set the value without "":

{
  conditions = { {
      isTrigger = true,
      operator = "<",
      property = "Einspeisung",
      type = "global-variable",
      value = -300
    } },
  operator = "all"
}

But this doesn't work at all. 

 

Why does this simple scene not work?

 

Best Regards

11 answers to this question

Recommended Posts

  • 0
Posted

Not sure what comparing values (I am talking about global vats)  in left block a good idea 

  • 0
Posted (edited)

Use equal -->"==" or not equal --> "!=" to compare the values from a global variable in a condition.

Result is a boolean.

Then in your scene do the rest.

I don't know why you have only those two options (tested in a blockscene) but i guess it has something to do with the two types of variables or it is a bug ??

Edited by Lode
  • 0
  • Inquirer
  • Posted

    I think this is a functional limitation that a global variable could not be an numeric (integer) type.

    But why is that not documented on the LuA documentation page :-( 

     

    So for me it is a feature request :-)

     

     

     

    • 0
    Posted (edited)

    When you compare strings it works by comparing character by charcater..

    for example 

    "-99"<"-301"  is true because first character "-9" less than "-3"  and so on...

    You will have a lot of cases were this statement is true  ( less than "-300" )

     

    It could be a good idea to run this scene [see fibaro.scene(...)] when value less than -300, were you update  the global "Einspeisung". May be you don't need the global at all.

     

    Edited by cag014
    • 0
    Posted
    9 hours ago, funnyboy4711 said:

    But why is that not documented on the LuA documentation page :-(

    There is so much not documented, this is a "bug" in Fibaro !

    • 0
    Posted

    I am pretty sure its documented, see for yourself ;)

    Please login or register to see this link.



    If you like you can use the docs build in the gateway -> in Swagger:

    image.png.3f7b89c54ba52bb45845961e5d061045.png

    Please login or register to see this attachment.

    • 0
    Posted (edited)

    Yes it's a string type in the Global Variable.

    I would trigger on every change and check in the Lua code. First convert the Global Variable to an int with tonumber(var)

    Edited by Joep
    • 0
    Posted

    Documentation or not, it would be user friendly if something like

    Please login or register to see this code.

    generates an error if it's not allowed so people would quicker understand what the problem was...

    • 0
    Posted

    But you can compare strings that way, it is not an error. Lua compares strings in alphabetical order.

    Also in block scene only != and = operators are available to avoid confusion.

     

    I am not sure why you are searching for a problem where there really isn't one.

     

     

     

    • 0
    Posted
    22 minutes ago, m.roszak said:

    But you can compare strings that way, it is not an error. Lua compares strings in alphabetical order.

    Also in block scene only != and = operators are available to avoid confusion.

     

    I am not sure why you are searching for a problem where there really isn't one.

    Sorry, I stand corrected. I thought that it wasn't allowed in a condition and that it didn't work for him. 

    ...but still, no error message for ;-).

    Please login or register to see this code.

    Seems to be no validation for conditions besides them having to be Lua tables.

    • Like 1
    • 0
    Posted

    I fully agree that we have a lot of work to do in the system.
    I just assume that we are going in right direction if we are arguing about this kind of issues ;)

    • Like 4

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