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

Check if variable changed


Seraphim
 Share

Question

Hello Community,

 

how can I check if a variable changes? Something like: If variableX = change then....

 

Regards

Andreas

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Not quite sure what you are aiming at. But if you use lua in your Homecenter 2, then you can trigger a scene, if a variable change.

 

--[[
%% autostart
%% properties
%% weather
%% events
%% globals
Ichange
--]]

 

In this example, the scene is triggered every time the global variable Ichange change its value.

Edited by Thomasn
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Hi Thomasn,

     

    this looks like a code from HC2 LUA, is this still working on HC3?

     

    I simply want to check (in a QuickApp and/or a scene) if a variable has change to trigger something.

     

    Example1:

    Trigger: var_timeofday changes

    Event: turn a device on/off

     

    Example2:

    If Then: If var_timeofday = change then turn on device

     

    Maybe there is something simple as you wrote above or something like fibaro.variablchange or self:variablechange

     

    Regards

    Andreas

    Link to comment
    Share on other sites

    • 0
    46 minutes ago, Seraphim said:

    Hi Thomasn,

     

    this looks like a code from HC2 LUA, is this still working on HC3?

     

     

    I do not have, or plan to have, a Homecenter3. It is too faulty. 

     

    You are right. It is LUA code rom a Homecenter2. Your signature suggest that you use a Homecenter2 too. My mistake.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Just now, Thomasn said:

    Your signature suggest that you use a Homecenter2 too.

     

    This is not changeable to HC3 right now, sorry, my fault, too.

     

    If there was a way to check for a change in HC2 I would expect something like this in HC3, too. Maybe someone else has a suggestion for me.

    Link to comment
    Share on other sites

    • 0

    You can do it by defining  trigger as global  variable, but to check non existing value. In this case any change in variable will trigger the scene.

    use condition below

    {

    isTrigger = true, 

    type = "global-variable" ,

    property = "variable_name" ,

    operator = "!=" ,

    value = "bla-bla"

    }

    Link to comment
    Share on other sites

    • 0

    what's wrong with variable check as trigger?

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0
    12 hours ago, jjacques68 said:

    maybe without :

    Please login or register to see this code.

    if you just have one...

    !!!???

     

    you can use any, it does not matter here, because 1 from all is still all, and any from 1 is still any/all.

    One have to use Operator - exception is just {} which then will be completely ignored by pre-trigger engine (which checks trigger and conditions and store pre-trigger results in trigger tabel which will then be evaluated by the lua engine, this is how HC3 save lot of memory and does not start anything - like it did on HC2 - just to check that condition has been not given. Of course one can still use conditions in the lua Code itself, but as it is somehow possible, it is better to have them on left side, together with triggers). 

     

    Please login or register to see this image.

    /monthly_2020_03/image.png.bbbc45ee633b3881d7eacb69d881d1cc.png" />

     

    Edited by tinman
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • All this works in a scene perfectly, but how to check a changed variable in a QuickApp?

     

    E.g: I have a global variable to set the time of the day. This variable is set by a scene that is triggered by different events (motion sensors, sleep sensor etc.). Now I want to read the actual value in a QuickApp, but I only get the last value, that was reported during the OnInit or when I press a Update-Button. But I do not want to press a button, I want the label to be updated automatically.

    Link to comment
    Share on other sites

    • 0
    8 minutes ago, Seraphim said:

    All this works in a scene perfectly, but how to check a changed variable in a QuickApp?

     

    E.g: I have a global variable to set the time of the day. This variable is set by a scene that is triggered by different events (motion sensors, sleep sensor etc.). Now I want to read the actual value in a QuickApp, but I only get the last value, that was reported during the OnInit or when I press a Update-Button. But I do not want to press a button, I want the label to be updated automatically.

     QA have no loop, you have to create your own loop, and check there the variables value. You can as well call from Scene (which in your case does change the variable, btw. if you don't store anything except the fact that something changed, use custom Events) your custom QA function. 

    More about what has been already discovered / tested -> 

     

    Edited by tinman
    Link to comment
    Share on other sites

    • 0

    Single condition can look like this:

    { type = "device", id = 25, property = "value", operator = "==", value = true, isTrigger = true }

    Works without operator also, but I suggest to follow @tinman suggestion to use operator in any case.

    Edited by cag014
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks tinman, this was the "trigger" I needed to think about it in a different way. I just update the QA when the scene changes the variable.

    Edited by Seraphim
    Link to comment
    Share on other sites

    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.

     Share

    ×
    ×
    • Create New...