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

Slider LUA trigger


seiq

Question

Is there a way to determine whether a virtual device slider was changed by physically moving the slider or whether it was updated with LUA?

This is for a now playing progress bar. In the slider's LUA script I want to ignore when the slider was updated by the main loop LUA code.

 

fibaro:getSourceTrigger() sadly doesn't work for virtual devices.

 

UPDATE:

Issue resolved.

Use fibaro:call(id, "setProperty", "ui.Slider1.value", position) to change the value and position of a slider without running the code in the slider.

The slider on the web interface may not move without refreshing the page when this is called but it does work.

Edited by seiq
Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

For triggering in Virtual Devices I use getModificationTime or getGlobalModificationTime.

 

For example, for triggering when a global variable is changed:

 

        -- Detecting global variable change and get value
function globVarChange(globVar, secMin, secMax, debugShow)
  local globVarChanged = false;
  local lastChangeGlobVar = tonumber(((os.time()) - tonumber(fibaro:getGlobalModificationTime(globVar))));
  if lastChangeGlobVar > secMin and lastChangeGlobVar <= secMax then
    globVarChanged = true;
    if debugShow then fibaro:debug('<span style="color:green">Global variable</span><span style="color:yellow"> '..globVar..' </span><span style="color:orange">Change state detected</span>') end;
    end
  if globVarChanged or globVarValue == nil then
    globVarValue = fibaro:getGlobal(globVar);
    if debugShow then fibaro:debug('<span style="color:green">Global variable</span><span style="color:yellow">  '..globVar..' </span><span style="color:green"> status value: </span>'..'<span style="color:yellow">'..tostring(globVarValue)..'</span>') end;
    end
  return globVarChanged, globVarValue or 0
  end
 

globVar = Global Variable name (string)

secMin = Low value (number, time in seconds) when the function has to be executed

secMax = High value (number, time in seconds) when the function has to be executed

debugShow = Enable (true) or disable (false) debug messages

EDIT: Returning values:

globVarChanged = When changed detected true, when not false

globVarValue = Value of global variable after the change

 

For example, if you want to trigger as fast as possible then secMin = 0 and secMax = 3. If you want to wait for a another process to finish, say after 10 seconds, then secMin = 10 and secMin = 13.

 

Beware that a trigger in a VD is not as quick as a scene trigger. The maximal delay is the Main Loop execution delay which is 3 seconds. That's why you have to make a secMin and a secMax value range of 3 seconds.

 

Also be aware that you be carefull to use fibaro:sleep() or other delaying technics in you mainloop without keeping the consequences for the secMax value in Mind.

 

It's just an example, I hope this is what you meant.

Please login or register to see this image.

/emoticons/default_icon_wink.gif" alt=";-)" />

Edited by Lambik
Link to comment
Share on other sites

  • 0
  • Inquirer
  • It's just an example, I hope this is what you meant.

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Thanks Lambik, but not what I'm after sorry.

    My idea with the getSourceTrigger() method working in the LUA code for a VD slider (or button) would be that it would return { type="other" } when the slider was moved using the GUI and return { type="property", propertyName="value", deviceID=id } when the slider value was changed using fibaro:call(vdID,"setSlider", "1", position) from the main loop of the virtual device.

    This is so the main loop can update the progress slider value without causing the code in the slider to run.

    Worked this out by using fibaro:call(vdID, "setProperty", "ui.progressSlider.value", 50) which doesn't cause the slider's LUA code to run. Tried this initially but when I was testing using the web interface it didn't look like "setProperty" moved the slider. Turns out it does and is just a bug in the web interface. Need to refresh the page for the slider position to be updated. Mobile apps work fine.

    • Like 1
    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.

    ×
    ×
    • Create New...