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

Setting up a Virtual Sensor Device


Question

Posted

I am tring to set up a virtual device as a binary sensor

1. I create the Quick App device alright

2. But when I add the Lua device code, nothing happens as I am supposed to get "open" and "closed" buttons - but nothing

3. The simple code to set this up is

 
 
function QuickApp:onInit()
    self:debug("Quick App Initialized")
    
    -- Add Open button
    self:addButton("openButton", "Open", function()
        self:openButtonClicked()
    end)
    
    -- Add Closed button
    self:addButton("closedButton", "Closed", function()
        self:closedButtonClicked()
    end)
end
 
-- Function to handle the "Open" button press
function QuickApp:openButtonClicked()
    local virtualSensorID = 330 -- Replace with your virtual sensor ID
    fibaro.call(virtualSensorID, "Open")  -- Assuming your virtual sensor uses "Open" as an action
    self:debug("State set to Open")
end
 
-- Function to handle the "Closed" button press
function QuickApp:closedButtonClicked()
    local virtualSensorID = 330 -- Replace with your virtual sensor ID
    fibaro.call(virtualSensorID, "Closed")  -- Assuming your virtual sensor uses "Closed" as an action
    self:debug("State set to Closed")
end

4. What Am I doing wrong

Appreciating any help

2 answers to this question

Recommended Posts

  • 0
Posted (edited)
On 8/6/2024 at 4:54 AM, Ronald H said:

I am tring to set up a virtual device as a binary sensor

1. I create the Quick App device alright

2. But when I add the Lua device code, nothing happens as I am supposed to get "open" and "closed" buttons - but nothing

3. The simple code to set this up is

 
 
function QuickApp:onInit()
    self:debug("Quick App Initialized")
    
    -- Add Open button
    self:addButton("openButton", "Open", function()
        self:openButtonClicked()
    end)
    
    -- Add Closed button
    self:addButton("closedButton", "Closed", function()
        self:closedButtonClicked()
    end)
end
 
-- Function to handle the "Open" button press
function QuickApp:openButtonClicked()
    local virtualSensorID = 330 -- Replace with your virtual sensor ID
    fibaro.call(virtualSensorID, "Open")  -- Assuming your virtual sensor uses "Open" as an action
    self:debug("State set to Open")
end
 
-- Function to handle the "Closed" button press
function QuickApp:closedButtonClicked()
    local virtualSensorID = 330 -- Replace with your virtual sensor ID
    fibaro.call(virtualSensorID, "Closed")  -- Assuming your virtual sensor uses "Closed" as an action
    self:debug("State set to Closed")
end

4. What Am I doing wrong

Appreciating any help

Where did you get this code from? This code can not be good. What is self:addButton ?????

 

I dont understand the logic at all. This is not a good code for a sensor.

First of all, a sensor is not an actor, it is a passive device, so it has some states but has no actions to perform. You can change its state upon some other events or manually calling manually self:updateProperty("value", true/false).

If you create a Quickapp and select a device type for binary sensor, you will get a binary sensor type device but it will do nothing on its own.

You need to define upon what event should it change its state.

If you want to simulate its state change, just create two buttons in editor, / one for opened state, one for closed state

Then create two callbacks for onReleased button click handling function.

Example

Please login or register to see this code.

After this when you click on these buttons the sensor state will change to the corresponding value.

 

I am attaching for you a simple example QA. Just download it, and it will work.

 

 

 

Please login or register to see this attachment.

Edited by Neo Andersson
  • Like 1
  • 0
  • Inquirer
  • Posted

    Neo. Thank you very much for your response. I appreciate your help

    Regards Ron H.

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