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

How do I find all devices of a specific type with LUA script


Guest b95_lun

Question

Guest b95_lun

Hello All,

I am new to HC2 but I am starting to try the LUA script to create different logic.

I would like to create a script that will arm all my motion and door sensors.

I would like to avoid to explicitly identify each device. Is it possible with LUA script to find all devices of a specific type?

Maybe loop through all devices and check their type?

/Niklas

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

The only way I can think in current beta is

Please login or register to see this code.

I am sure there was a call in docs to get a table of devices but can't find it or any way to get max id without a db read.

You may need to look for other classes (113?)and I am not sure if 1 is arm for all devices or if the armed action is working.

Can you give this a test?

Link to comment
Share on other sites

  • 0
Guest b95_lun
  • Inquirer
  • Thanks Robert,

    Good idea to use the classes, it was new to me

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    It managed to find my two Fibaro door/window sensors and my two Everspring SF812-1 smoke detectors but it didn't find my two Everspring HSM02 Door/Window sensors.

    So I found using the classes a bit cumbersome and will probably use an array where I need to add new sensors manually.

    It would have been nice if I could have used Fibaror's "Device kind", door_sensor...

    I needed to make a small change to your script to be able to arm the sensors. I used the action setArmed instead of Armed.

    fibaro:call(i,'setArmed' , "1" )

    Link to comment
    Share on other sites

    • 0

    Normally you should use function fibaro:getType(ID) but it's not working in current Beta. It's corrected in the coming next release (see Bugtracker).

    Robert - thanks for the code it's very helpful.

    PS

    Here is a part of a definition of properties of a door_sensor in regard of motion sensor.

    Properties of other devices you can get with http command /api/devices?ID=xx or /api/devices?type=door_sensor etc

    {

    "id":22,

    "name":"Drzwi ogrodowe",

    "roomID":2,

    "type":"door_sensor",

    "properties":{

    "UIMessageSendTime":"0000-00-00 00:00:00",

    "armed":"0",

    "batteryLevel":"83",

    "classConfigure":"0,0,2,2,0,2,2,2,2,0,0",

    "classGeneric":"48",

    "classSupport":"43,48,112,114,122,128,132,133,134,156,239",

    "classVersion":"1,1,1,1,1,1,1,2,1,1,1",

    "dead":"2",

    "deviceControlType":"0",

    "deviceIcon":"24",

    "disabled":"0",

    "emailNotificationID":"6",

    "emailNotificationType":"0",

    "endPoint":"0",

    "isBatteryOperated":"1",

    "needConfigure":"5",

    "type":"door_sensor",

    "nodeID":"29",

    "parametersTemplate":"204",

    "parentID":"1",

    "pollingRetryError":"",

    "pollingTime":"1361212698",

    "pollingTimeNext":"1361533492",

    "pollingTimeSec":"0",

    "productInfo":"1,15,7,0,16,0,2,1",

    "pushNotificationID":"4",

    "pushNotificationType":"0",

    "requestNodeNeighborState":"0",

    "requestNodeNeighborStateTimeStemp":"0",

    "sceneActivation":"0",

    "sceneDimingDuration":"0",

    "showChildren":"0",

    "smsNotificationID":"6",

    "smsNotificationType":"0",

    "sortOrder":"999",

    "type":"32",

    "unit":"",

    "userDescription":"",

    "value":"0",

    "wakeUpTime":"4000",

    "zwaveCompany":"Fibar Group",

    "zwaveInfo":"3,3,42",

    "zwaveVersion":"2,1"

    },

    "actions":{

    "armed":1,

    "firmwareUpdate":1,

    "pollingTimeSec":1,

    "requestNodeNeighborUpdate":0,

    "setArmed":1,

    "setWakeUpTime":1,

    "wakeUpTime":1

    }

    Link to comment
    Share on other sites

    • 0
    Guest b95_lun
  • Inquirer
  • Thanks Richo

    the fibaro:getType(ID) seems to work on the latest beta, 3,486

    You probably know but I found that notepad++ has a Json plugin which makes it a lot easier to read the out put from Json API's

    Is it possible to listen for change on all devices of a specifc type something like:

    --[[

    %% properties

    door_sensors

    %% globals

    --]]

    I would like to create a script which I don't have to update when I add new devices

    Link to comment
    Share on other sites

    • 0

    b95_lun, right now no, but your idea is great we gonna put it on list to do

    Link to comment
    Share on other sites

    • 0
    b95_lun, right now no, but your idea is great we gonna put it on list to do

    Any clue when this nice feature is to be available in lua scripts?

    Link to comment
    Share on other sites

    • 0

    Hi all

    The getType function is not the most appropriate !!

    I compare the result return by getType with "binary_light" and I get many devices that are not lights. In fact, this value can be applied to all on/off switchs

    So is there a way to found only devices that are lamps or lights (property "Controlled Device" = Garden lamp, bedsidelamp, light, etc) ?

    Thanks

    David

    Link to comment
    Share on other sites

    • 0

    Binary_light are all the switches.

    Dimmable_light are all the dimmers.

    door_sensor, window_sensor, motion_sensor is what you mostly need for your alarm.

    The one that you are looking for is the DeviceControlType. Which you select yourself on the advanced page of a device.

    That is a number. Which is probably an enum. So you have to check which number is which type yourself.

    Hope it helps

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Ps. Irreverent but this was my 300st post on this forum

    Please login or register to see this image.

    /emoticons/default_tongue.png" alt=":P" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Link to comment
    Share on other sites

    • 0

    Hi All

     

    I turn again this topic....

     

    There is no news regarding a way to run a loop on a specific type of devices ?

     

    Some of my devices disappear so I'm tired to update all my scenes related to this devices because I hardcoded device IDs in them. So I would like a more flexible solution

     

    Thanks

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