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


  • 1

Help with copy value to a local variable with a virtual button


Question

Posted (edited)

I have a meter whose value I display with a Label in a VD with following code: fibaro: call (fibaro: getSelfId (), "setProperty", "ui.Label1.value", fibaro: getValue (262, "energy") .. " kWh ");.

 

I am wondering if anyone can help me develop the LUA code with an additional Label and virtual button in VD.

 

I have the following idea for the function. When the button is pressed, in my case, "value 262" is copied to a local variable that can be called "old value". The new label shows the current value minus the "old value" i.e., my energy use since the last reset.

 

Also believe me to have read somewhere that Fibaro has a command that shows the timestamp of an event which in my case could show when "old value" was last saved

 

Does anyone have a solution to this challenge?

Edited by Rogga10000
Clarification of my question

4 answers to this question

Recommended Posts

  • 0
  • Inquirer
  • Posted

    I have had some success with my project.

     

    To be able to move on, I wonder if anyone can show me how I can change the value of a local variable when "Reset button" is "ON" on a virtual button in the same VD as the local variables. When pressing a virtual button in the VD I wish to save OldValue = NewValue.

     

    The value I want in the end is NewValue-OldValue. After "Reset" NewValue=OldValue=0. After that the NewValue will increase with the energy consumption...

    • 0
    Posted

    set it in a timefunction

     

    local sourceTrigger = fibaro:getSourceTrigger()
    local ID                = "ID number"
    local B                   = fibaro:getValue(ID, "energy")
    ------------------------------------------------------------------
    function script()
        A = fibaro:getValue(ID, "energy")
    ------------------------------------------------------------------
        C = (A - B)
        B = A
    ------------------------------------------------------------------
    setTimeout(script, 60*1000)
    end
    ------------------------------------------------------------------
    if (sourceTrigger["type"] == "autostart") then script() end

     

    • 0
  • Inquirer
  • Posted

    Thanks Kage for your response,

    I have tried different versions of this proposal without succeeding in making it work. If you can develop your answer a little, it would be very appreciated.

     

    This is the code I have in the VD that does not work

     

    --[[
    %% properties
    262 energy
    %% globals
    --]]

    ---------------------------------------------------------------------------------------------------------

    --- To see values of local varables in Label

    fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label1.value", A);

    fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label2.value", B);
    fibaro:call(fibaro:getSelfId(), "setProperty", "ui.Label3.value", C);

    ---------------------------------------------------------------------------------------------------------

    local sourceTrigger = fibaro:getSourceTrigger()

    local ID = "262" -- Should it be the ID of the VD (325) or the energy meter (262)?
    local B = fibaro:getValue(ID, "energy")
    ------------------------------------------------------------------
    function script()
    local A = fibaro:getValue(ID, "energy")
    ------------------------------------------------------------------
    local C = (A - B)
    local B = A
    ------------------------------------------------------------------
    setTimeout(script, 60*1000);
    end
    ------------------------------------------------------------------
    if (sourceTrigger["type"] == "autostart") then script() end

    ----------------------------------------------------------
     

    Please login or register to see this image.

    /monthly_2019_08/image.png.8db9c2a5724d4e488f63e907a48c8376.png" />

    • 0
    Posted

    The script was for a scene, from there you can set it in a VD like

     

    add to scene

    local selfId = "your ID_VD"

    fibaro:call(selfId, "setProperty", "ui.lblEnergie.value", C)

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