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

Anyone know how to determine the current profile on HC3?


Question

Posted

I've seen quite a bit of mention of fibaro.activeProfile() from experts like @jgab, but this code for example fails with attempt to call a nil value (field 'activeProfile').
Has the function been dropped?
 

-- 1) figure out what profile is active
local activePid = fibaro.activeProfile() -- returns current profile ID
local activeProf = fibaro.profileIdtoName(activePid) -- turns that into "Home", "Away", "Vacation", etc.

2 answers to this question

Recommended Posts

  • 0
Posted

These functions are part of the fibaroExtra library of jgab?

  • 0
  • Inquirer
  • Posted (edited)

    They are -  just realised that too! Thanks @SmartHomeEddy

    It works when these are included (changed for scene use not QA)

     

    function fibaro.profileIdtoName(pid)
    if type(pid) ~= "number" then
    error(("bad argument #1: expected number, got %s"😞format(type(pid)), 2)
    end
    for _,p in ipairs(api.get("/profiles").profiles or {}) do
    if p.id == pid then return p.name end
    end
    end
     
    function fibaro.profileNameToId(name)
    if type(name) ~= "string" then
    error(("bad argument #1: expected string, got %s"😞format(type(name)), 2)
    end
    for _,p in ipairs(api.get("/profiles").profiles or {}) do
    if p.name == name then return p.id end
    end
    end
     
    function fibaro.activeProfile(id)
    if id then
    if type(id)=='string' then id = fibaro.profileNameToId(id) end
    assert(id,"fibaro.activeProfile(id) - no such id/name")
    return api.put("/profiles",{activeProfile=id}) and id
    end
    return api.get("/profiles").activeProfile
    end

     

    Edited by NorthernRough

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