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

Checking windows/doors status HC3 Lua


Question

Posted

How can I check opening sensors status  and get back their values (opened or closed), I have a lot of windows sensors. 

For  example getting device values from a global variable list ?

 

 

 

8 answers to this question

Recommended Posts

  • 1
  • Inquirer
  • Posted

    I tried the following QA:

    but gave me this error message>> ERROR :  Wrong parameter type, number required. Provided param 'table: 0xaaab03264ec0' is type of table

     

    ---------

     

    local sensorValues = {}
    local function checkSensors(self)
        local sensors = api.get("/devices?baseType=com.fibaro.doorWindowSensor&enabled=true")
        for _,sensor in ipairs(sensors) do
            if sensorValues[sensor.id] ~= sensor.properties.value then
                sensorValues[sensor.id] = sensor.properties.value
                self:sensorState(sensor,sensor.properties.value)
            end
        end
        setTimeout(function() checkSensors(self) end1000)
    end
     
    function QuickApp:sensorState(sensor,state)
        local name = hub.getName(sensor)  -- > ERROR :  Wrong parameter type, number required. Provided param 'table: 0xaaab03264ec0' is type of table
        hub.debug(__TAG,name .. " is " .. (state and "open" or "closed") .. " now")
        hub.setGlobalVariable("sensors",json,encode(sensorValues))
    end
     
    function QuickApp:onInit()
        checkSensors(self)
    end

     

    • 0
    Posted

    Please login or register to see this code.

     

    This reads all enabled sensors and checks per sensor if it is open (value = true) and reports the name in the log.

    • 0
    Posted

    If you need to continously check in a QA you do like this

    Please login or register to see this code.

     

    If you have the deviceIDs in a pre-made table its a bit different

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted
    7 hours ago, jgab said:

    If you need to continously check in a QA you do like this

    Please login or register to see this code.

     

    If you have the deviceIDs in a pre-made table its a bit different

    Please login or register to see this code.

     

     

     

    Thank you very much!

    How can I put for example the opened ones into a global variable?

    • 0
    Posted
    14 hours ago, iTibor said:

     

     

    Thank you very much!

    How can I put for example the opened ones into a global variable?

    Want to put them as a table in one global variable or each in a separate global variable?

    All in one global (last example with sensor IDs in a table)

    Please login or register to see this code.

    Each in a separate global  (last example with sensor IDs in a table)

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    Hi

     

    If it is a QA doesn't draining the batteries, I mean checking their status?  

     

     

    • 0
    Posted
    56 minutes ago, iTibor said:

    I tried the following QA:

    but gave me this error message>> ERROR :  Wrong parameter type, number required. Provided param 'table: 0xaaab03264ec0' is type of table

     

    ---------

     

    local sensorValues = {}
    local function checkSensors(self)
        local sensors = api.get("/devices?baseType=com.fibaro.doorWindowSensor&enabled=true")
        for _,sensor in ipairs(sensors) do
            if sensorValues[sensor.id] ~= sensor.properties.value then
                sensorValues[sensor.id] = sensor.properties.value
                self:sensorState(sensor,sensor.properties.value)
            end
        end
        setTimeout(function() checkSensors(self) end1000)
    end
     
    function QuickApp:sensorState(sensor,state)
        local name = hub.getName(sensor)  -- > ERROR :  Wrong parameter type, number required. Provided param 'table: 0xaaab03264ec0' is type of table
        hub.debug(__TAG,name .. " is " .. (state and "open" or "closed") .. " now")
        hub.setGlobalVariable("sensors",json,encode(sensorValues))
    end
     
    function QuickApp:onInit()
        checkSensors(self)
    end

     

    because you are mixing the two examples. The sensorSate(sensor, state) function requires the version with devices IDs in a table/list as mentioned in the example.
    A sensorState function working with the other version would look like

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted
    On 8/14/2023 at 1:20 PM, jgab said:

    because you are mixing the two examples. The sensorSate(sensor, state) function requires the version with devices IDs in a table/list as mentioned in the example.
    A sensorState function working with the other version would look like

    Please login or register to see this code.

     

    Thanks!  It work

     

    if i want to get only the open ones how can I get? 

    something like this?

    if sensor.state == open then 

     

    end

     

     

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