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


  • 2

Lua code to set a device parameter


Hellisloose
 Share

Question

Hi, I would like to set a device parameter thru either a virtual device (preferred) or a scene

In my example, I have a doorlock (IDLock 101) and would like to set parameter number 1 (autolock mode)

The parameter can set the lock to autolock(arm or not armed) or manual (arm or not armed)

Please login or register to see this link.

Please login or register to see this image.

/monthly_2018_04/image.png.7decf6642f11dea987ab37f10906dcac.png" alt="image.png.7decf6642f11dea987ab37f10906dcac.png" />

Is it possible thru LUA or do I need to set it another way?

 

Regards

 

 

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 1

This comes with absolutely no warranty.

 

To avoid sending parameters to the wrong device, the code checks the product ID...

 

Check this line:

    productInfo = "1,15,1,0,16,10,2,2" -- This is a FGD 211, v2.2

 

So, for your door lock, you have to go to //<your_ip>/api/devices/<device id> eg http://192.168.0.1/api/devices/8 and find that string and modify that line.

 

The api.get call is undocumented and might change if Fibaro updates the HC firmware.

Please login or register to see this code.

 

  • Thanks 3
Link to comment
Share on other sites

  • 0

Hi!

 

no. and as I know not roadmap here.

 

it' will be useful for using for some devices - for example - change sound 

Link to comment
Share on other sites

  • 0
37 minutes ago, petergebruers said:

The api.get call is undocumented and might change if Fibaro updates the HC firmware.

 

wow! haw-haw! 

Thank you!

Link to comment
Share on other sites

  • 0

Just tried to override the "deviceGroup" with no luck but also no fail message - any idea...?!

Link to comment
Share on other sites

  • 0
On 4/24/2018 at 10:19 AM, petergebruers said:

/<your_ip>/api/devices/<device id>

A small tweak to the code so that is automatically handles parameters of different size (i.e. number of bytes):

 

function modifyParameter(id,parameterID,targetValue,parameterSize)
    local productInfo
      if (id == xx) then
        productInfo = "1,2,3,4,5,6,7,8"
    elseif (id == xx) then
        productInfo = "1,2,3,4,5,6,7,8"
    elseif (id == yy) then
        productInfo = "1,2,3,4,5,6,7,8"
    elseif (id == zz) then
        productInfo = "1,2,3,4,5,6,7,8"
      end

..

etc
..  
    device = api.get("/devices/" .. id)
      if not device then
        fibaro:debug('Device ID ' .. id .. ' not found in database')
    elseif device.properties.productInfo ~= productInfo then
        fibaro:debug(string.format("Device %d property prodInfo %s differs from %s.\nNothing written to device.",id,device.properties.productInfo,productInfo)) return
    else
        local parameter
           for _,v in pairs(device.properties.parameters) do
            if v.id == parameterID then
                parameter = v
                break
            end
          end
         if not parameter then
            parameter={id = parameterID, size = parameterSize}
            table.insert(device.properties.parameters, parameter)
               fibaro:debug('Device ' .. device.id .. ', new Parameter ' .. parameterID .. ' added with size ' .. parameterSize .. ' bytes')
          end
          local settings = {id = device.id, properties = {parameters = device.properties.parameters}}
        if (parameter.value == targetValue) then
               fibaro:debug('Device ' .. device.id .. ', Parameter ' .. parameterID .. ', already set to value ' .. targetValue)
        else
             parameter.value = targetValue
               fibaro:debug('Device ' .. device.id .. ', Parameter ' .. parameterID .. ', changed to new value ' .. targetValue)
        end
          local ok, result = pcall(api.put, "/devices/" .. id,settings)
         if not ok then
            fibaro:debug("api call failed: "..result)
            return
          end
      end
end
 

..

modifyParameter(xx,1,2,1)
modifyParameter(xx,2,3,1)
modifyParameter(xx,3,255,1)
modifyParameter(xx,4,1,1)
modifyParameter(xx,5,8,1)
modifyParameter(yy,1,2,1)
modifyParameter(yy,2,3,1)
modifyParameter(yy,3,255,1)
modifyParameter(zz,1,1,1)
modifyParameter(zz,2,8,1)
..

etc.

  • Thanks 1
Link to comment
Share on other sites

  • 0

Hello, how to read an "advanced" parameter that needs "read only" flag in order to be updated?

 

I was able to get the values of interested parameters with following code, but the values are "last read" values and not the updated ones. I am trying to read produced energy from a Widom energy driven switch

 

 

device=api.get("/devices/" .. 174)


local parameter1
local parameter2

  for _,v in pairs(device.properties.parameters) do
    if v.id==54 then
      parameter1=v
    elseif v.id==55 then
      parameter2=v
      break
    end
  end


fibaro:debug(parameter1.value)
fibaro:debug(parameter2.value)

 

Thank you in advance for your help

Edited by fantomas
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...