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

Triggering variable name from fibaro:getSourceTrigger?


Question

Posted

Hi,

Hoping somebody can help me with this LUA code. I've got a Scene that is triggered by any of a list of Global variables having their value set to "true". When the scene is triggered I want to use fibaro:getSourceTrigger to find out the name of the variable that sets off the scene. Here's the Lua code I've got:

Please login or register to see this code.

The problem is:

Please login or register to see this code.

is always returning...

Please login or register to see this code.

Whereas I am expecting it to return the name of the Global variable that caused the Scene to trigger - i.e.

Please login or register to see this code.

Does anyone know if I'm doing something wrong in the Lua code, or if this is a bug on Fibaro's side? I'm using v3.548

Thanks!

Recommended Posts

  • 0
Posted

Global variabe can't trigger scene, add a timer who check every minute.

  • 0
  • Inquirer
  • Posted

    Are you sure?

    It says they can on

    Please login or register to see this link.

    Please login or register to see this code.

    Also in the explanation of the functionality of the

    Please login or register to see this code.

    call in the documentation it explicitly mentions being able to have a Global variable trigger a scene, and the

    Please login or register to see this code.

    call to get the triggering variable...

    Unless I'm misunderstanding it it looks like it should work...

    Also the graphical block scene builder allows you to build scenes triggered by changes in Global variables (and I've got scenes working based on that)...

    The problem/bug/misunderstanding seems to be in how to use

    Please login or register to see this code.

    to extract the name of the variable that caused the scene to trigger when the scene can be triggered by multiple Global variables OR'd together...

    • 0
    Posted

    I have a plug with power meter on the television socket.

    A while ago I tested detecting the television switching on on the basis of the use of power.

    I do not currently have the scene as I am halfway through a rebuild but it worked fine. Not a difficult script.

    [ Added: 2013-08-06, 13:56 ]

    It says they can on

    Please login or register to see this link.

    if you expect everything on HC2 to work as documented, you will have a sense of humor loss :->

    My triggers on globals are working

    try

    Please login or register to see this code.

    and i think the keyname is name

    • 0
  • Inquirer
  • Posted

    Hi,

    Thanks for your responses. In terms of detecting the TV turning on I have another script that runs constanting pinging the IP addresses of the TV's. This sets the value of the corresponding Global Variable to true or false. This works fine, so whilst I could go and purchase Fibaro Wall Plugs to achieve the same end (via energy monitoring), I don't think that's necessary.

    What I'm really asking is is there a bug in Fibaro's implementation of fibaro:getSourceTrigger()?

    Consider this simple scene:

    Please login or register to see this code.

    To activate the scene I change the value of the Global Variable "MyGlobalVariable" from 'false" to "true". This, correctly, triggers the scene to execute.

    According to Fibaro's documentation the result of trigger["varName"] should be the name of the Global Variable that triggered the scene - i.e. the string "MyGlobalVariable", however trigger["varName"] always returns "nil".

    The documentation is shown

    Please login or register to see this link.

    I'm really trying to understand whether the implementation of fibaro:getSourceTrigger()["varName"] has a bug in it, or whether my understanding of how it is mean't to work is incorrect...

    Thanks in advance!

    • 0
    Posted

    see edit on my post should fix this problem and allow you to find other

    key name is "name"

    Please login or register to see this code.

    • 0
    Posted

    Shad, not true, variable is working as a triger

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    @robmac You're a genius! You're absolutely right. Key is "name" rather than "varName" (the Fibaro Docs website incorrectly says "varName"). I really appreciate your help - thought I was going mad!

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    @A.Socha Thanks for clarifying!

    • 0
    Posted

    Hi A.Socha

    I had to go and check though... he had me worried.

    Will there be an update on LUA api docs? There are a few calls I have discovered that are not in the docs and errors like this one.

    [ Added: 2013-08-06, 14:21 ]

    You're a genius!

    Please login or register to see this image.

    /emoticons/default_icon_confused.gif" alt=":-?" /> you would not say that if you knew me but thanks
    • 0
  • Inquirer
  • Posted

    Couple of other quick questions:

    1) Is it possible to trigger a scene on ANY change in Global Variable value (as opposed to the variable changing to a specific value)?

    2)Is it possible to extract the value of a Global Variable prior to the change that triggered the scene, i.e. in my example above the variable was changed from "false" to "true" so a call to fibaro:getGlobalValue() within the scope of the scene returns the new value it was set to i.e. "true" - is it possible to value the value the Global Variable was before the Scene was triggered?

    Thanks!

    • 0
    Posted
    Couple of other quick questions:

    1) Is it possible to trigger a scene on ANY change in Global Variable value (as opposed to the variable changing to a specific value)?

    I think your code already does...

    2)Is it possible to extract the value of a Global Variable prior to the change that triggered the scene, i.e. in my example above the variable was changed from "false" to "true" so a call to fibaro:getGlobalValue() within the scope of the scene returns the new value it was set to i.e. "true" - is it possible to value the value the Global Variable was before the Scene was triggered?

    !

    I wish... store last value in another global? but not very nice

    • 0
    Posted
    Shad, not true, variable is working as a triger

    Please login or register to see this code.

    I was sure we can't trigger scene, I don't remember where I read that.

    Ok my bad, so I can optimize some of my lua code

    Please login or register to see this image.

    /emoticons/default_biggrin.png" alt=":D" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    • 0
    Posted

    Shad, you can from 3.5x

    • 0
    Posted

    Ok thanks.

    • 0
    Guest GrZeCh
    Posted
    Shad, not true, variable is working as a triger

    Please login or register to see this code.

    Does changing variable using variables panel or API should trigger this scene? I'm trying to trigger test scene which is almost identical to your example:

    Please login or register to see this code.

    Changing variable using API or variable panel does not do anything. Scene LUA code is being executed only when I press Run button from scene edit form.

    Regards

    EDIT: HC2 soft: 3.558

    EDIT2: I was trying also to determine trigger source using:

    Please login or register to see this code.

    but changing isItDarkOutside variable is not triggering anything. Only pressing run button in scene edit form or running it using fibaro:startScene(SceneID) is causing to display "Inne źródło" debug message.

    • 0
    Posted

    GrZeCh, and now do other scene who gonna change variable test_variable, change by panel will not work

    • 0
    Guest GrZeCh
    Posted
    GrZeCh, and now do other scene who gonna change variable test_variable, change by panel will not work

    IMHO changing global variable is changing global variable. It should not be narrowed only to some parts of how it is being changed. I just wanted to update my post because I was able to trigger scene by using fibaro:setGlobal(varName, value) function. Is there a place where I can find which global variable updates are executing triggers? For now only thing which is working is setGlobal global function. Changing global variable using variables panel or using API is not triggering anything.

    EDIT: Actually I see that there is a bug report for that:

    Please login or register to see this link.

    5 months old without any response and it even has my own comment (I was sure that it was solved but it looks it has been not).

    • 0
    Posted

    GrZeCh, we dont want to have madness in house when you press save in variable panel, about api is assigned ticket so you must wait

    • 0
    Guest GrZeCh
    Posted

    Why madness in house? If someone changes some variable then he is changing it for a reason.

    Of course it depends how you are handling saving variables and triggering scenes. I was thinking only for triggering when variable is changing to different value but it looks from your response that trigger is also executed when variable is changed to the same value am I right? If yes then maybe you could consider adding some possibility to trigger scenes only when changed variable has been altered to different value than it was before.

    • 0
    Posted

    GrZeCh, save in variable panel will start all scenes with variable that way it will be madness

    • 0
    Guest GrZeCh
    Posted

    Regarding saving in variables panel I was just curious but for API I'm interested (and I'm probably not the only one). Any ETA for that? Is there a really big difference in changing variable using API vs changing it using LUA? Doesn't it end in similar place when it comes to HC2 software coding?

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