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

11 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

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

This comes with absolutely no warranty.

 

 

Does this method still work with the latest firmware and I'm assuming/hoping it would work to set Parameter 13 to value=1?

I'm basically looking to be able to force dimmer 2 modules to recalibrate such that I can create a scene to recalibrate a bunch of dimmer 2 modules.  

 

The use case is that after a power cut or operating on a generator/backup power source the dimmer 2 devices need recalibrating (they basically strobe)

Once power is restored from the grid the lights strobe until a recalibration is forced. 
We thought we had fixed the problem by setting the dimmers to never automatically recalibrate but it appears to make no difference.

Link to comment
Share on other sites

  • 0
14 hours ago, tdielectrical said:

Does this method still work with the latest firmware

I don't know, I turned off my HC2 in 2019... but then again, not many fundamental updates for HC2 were posted after 2019

 

Try it. It is not terribly unsafe, I merely point out "it comes without warranty"

 

15 hours ago, tdielectrical said:

force dimmer 2 modules to recalibrate

That would work but keep in mind that, as soon as calibration starts, the module becomes unresponsive both locally and to Z-Wave commands. I imagine, that might cause issues.

 

15 hours ago, tdielectrical said:

We thought we had fixed the problem by setting the dimmers to never automatically recalibrate but it appears to make no difference.

I *think* I can confirm your observation, but I haven't done that kind of testing in many years, but here is what I remember.

 

Some people want to use this device (Dimmer 2) as a remote control... Without a load. But that does not work, because it tries to calibrate at power on and if it has no load it stays "turned off". Users tried all sort of parameter options and combinations, and IIRC you can make it work - once - with a load, power on, then remove the load. But after a power cut, under certain conditions, the Dimmer 2 decides to recalibrate and fails ... again. So that is not an ideal solution. Two options to solve this: either use "Bypass 2" as a "dummy" load (recommended by Fibaro) or use a different device like one of the recent double switches.

 

Maybe "Bypass 2" can help., or maybe it is the opposite, maybe a bypass makes it worse? It may depend on your load and generator. Many variables. To be tested...

 

I am not sure if there is a workaround, only a few users have talked about "generators and Dimmer 2" and the only thing I can find is "Dimmer 2 is sensitive to the frequency of the mains signal"

 

I am tagging @m.roszak - hoping he has some internal knowledge about this specific use case and problem 

  • Like 1
Link to comment
Share on other sites

  • 0
1 hour ago, petergebruers said:

 

I am not sure if there is a workaround, only a few users have talked about "generators and Dimmer 2" and the only thing I can find is "Dimmer 2 is sensitive to the frequency of the mains signal"

 

I am tagging @m.roszak - hoping he has some internal knowledge about this specific use case and problem 

 

Thank you for your response and advice, it is much appreciated. Obviously this is not really what I would call a solution, just a work around for one friend who has 30+ dimmers and is very tedious post a power cut to stop the lights strobing. They actually have a powerwall, but I see very similar results with a generator. 


In all combined cases, all dimmer 2 modules have loads attached and are not used in 2-wire method either. I believe there are a couple with bypasses attached (based on small loads) so it will be interesting to double check if those behave the same way.

 

You are also right about dimmer 2 modules being sensitive to the mains frequency. While running on a generator, the dimmer 2 devices can behave in various ways; not responsive at all (I think this is stuck in failed calibration state), flicker, strobe etc. The freq varies slightly on generator load and you can find that things may work perfectly when the generator is loaded at a specific value. Interestingly I have 1 or 2 dimmer 1 modules which don't suffer from the same problems and work perfectly while on the generator and after power is restored. I thought it might be more to do with the load than the dimmer module but as luck would have it, one is in a kitchen/diner area where the dimmer 1 and dimmer 2 modules not only have the same number of recessed LED lights, they are also from the same manufacturer.

 

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