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


  • 1

Quick Apps questions


tcviper

Question

Hello ?

If I want to make a Quick App (VD) with 2 buttons, what is the command to call for a http line?

So when button 1 is pressed I want deviceid XX to turn on ?

 

Thanks

Link to comment
Share on other sites

Recommended Posts

  • 0
  • Inquirer
  • I think I have it working, this is the code now:

     

    Please login or register to see this code.

     

    The only thing missing is that I have no idea how to let the device know the alarm is set.

    Link to comment
    Share on other sites

    • 0
    7 minutes ago, jgab said:

    if not I guess even the built in-buttons doesn’t work in the mobile app...?

    They do work, the example I've posted is fully functional. So the on/off button on my (android) phone works, as well as the on/off button in my browser, and both toggle if I click the button on the physical device (ESP module), but there can be a delay of up to 3 seconds because of the "polling" involved.

    Link to comment
    Share on other sites

    • 0
    On 2/12/2020 at 2:30 PM, tcviper said:

    I think I have it working, this is the code now:

    The only thing missing is that I have no idea how to let the device know the alarm is set.

     

    Progress! :-)

    In theory you should be able to get the "arm" property with something like 

    Please login or register to see this code.

    ...but I don't have an alarm so I don't know what the name of the prop is.

     

    On 2/12/2020 at 2:38 PM, petergebruers said:

    They do work, the example I've posted is fully functional. So the on/off button on my (android) phone works

    Yep, @tcviper seems to have made it work... now he only have to retrieve the arm prop of the alarm.

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Ok, @jgab the satel alarm has a device called 'Alarm IN'. When the alarm is activated that goes ON, when alarm is deactivated, it goes OFF.

     

    These are the device details: 

    Please login or register to see this code.

    So what can I add to the Quick app to let it know alarm has been set or not? (coming from this device id above?)

    Edited by tcviper
    Link to comment
    Share on other sites

    • 0
    13 minutes ago, tcviper said:

    Ok, @jgab the satel alarm has a device called 'Alarm IN'. When the alarm is activated that goes ON, when alarm is deactivated, it goes OFF.

     

    These are the device details: 

    Please login or register to see this code.

    So what can I add to the Quick app to let it know alarm has been set or not? (coming from this device id above?)

     

    So, fibaro.getValue(1082,"value") should get you the value. (also fibaro.getValue(1082,"state") could work?)

    It returns true or false.

    Btw, your Satel deviceID changing value all the time? it was 1147, now 1082?

     

    Wait, this is the QD you have defined yourself. 

    You need to access the property of the Satel devices - is that the 1147?

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Ha :) That is cause I deleted and re-added the Satel alarm plugin a few times :P

     

    And yes getvalue should do that, but how to implement that in the script above? :P (sorry not so good with this)

    Edited by tcviper
    Link to comment
    Share on other sites

    • 0
    Just now, tcviper said:

    Ha :) That is cause I deleted and re-added the Satel alarm plugin a few times :P

    ok, but 1082 seems to be the QD you have defined yourself. 

    You need to access the property of the Satel devices

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 21 minutes ago, jgab said:

    ok, but 1082 seems to be the QD you have defined yourself. 

    You need to access the property of the Satel devices

     

    No 1082 is the device id of the Satel Integra Alarm IN (which reflects if alarm is on or not). The Satel plugin does that :P

     

    If you would manually set the alarm (through  the panel on the wall) that Device will turn on. So you can see the alarm is on. However, you cannot use that device to actually turn it on, it only reflects the status.

    Edited by tcviper
    Link to comment
    Share on other sites

    • 0
    9 godzin temu, petergebruers napisał:

    Forgot to attach my example code... Credit wehre credit due, this code is the result of a cooperation of @AutoFrank, @petergebruers and some rework done by Fibaro, which is to say the main issue right now is lack of proper documentation of FQA aka "Fibaro Quick Apps"...

     

    Please login or register to see this attachment.

    I have Sonoff with AFE soft and I write it using the command: http://192.168.1.17/?device=relay&name=Power2&command=on

     

    In response, I receive data in the json format:

     

    { "Device", "relay", "name": "Power2", "command", "he", "value", "he", "status": "success"}

    I changed it in this script:

     

    --
    -- QuickApp created by Autofrank (Frank Smith) to control a Tasmota flashed switch
    -- This is not a finshed product but a way to understand the new QuickApps code stucture
    --
     
    -- Binary switch type should handle actions turnOn, turnOff
    -- To update binary switch state, update property "value" with boolean
     
    function QuickApp:turnOn()
    self:debug("binary switch turned on")
    self:sendCommand("/?device=relay&name=Power2&command=on", function()
    -- this will happen on http 200
    self:updateView("label", "text", "TURNED ON") -- think there is some issue in updateView method. We have some similar bug reported
    self:updateProperty("value", true) -- changing value shoud update device icon, work as a trigger in scenes ect.
    end)
    end
     
    function QuickApp:turnOff()
    self:debug("binary switch turned off")
    self:sendCommand("/?device=relay&name=Power2&command=off", function()
    -- this will happen on success http 200
    self:updateView("label", "text", "TURNED OFF") -- think there is some issue in updateView method. We have some similar bug reported
    self:updateProperty("value", false) -- changing value shoud update device icon, work as a trigger in scenes ect.
    end)
    end
     
    -- one method to send commands
    -- if http request returns 200, successCallback function will be called
    function QuickApp:sendCommand(query, successCallback)
    local url = "http://".. self:getVariable("IPAddress")
    url = url .. "" .. query
     
    self:debug("Sending command to:", url)
     
    self.httpClient:request(url,
    {
    options= {
    method = "GET"
    },
    success = function (response)
    if (response.status >= 200 and response.status < 300) then
    if successCallback then -- check if successCallback was provided
    successCallback()
    end
    end
    end,
    error = function (err)
    errorlog("Error: " ..err)
    end
    })
    end
     
    function errorlog(str)
    print(str)
    end
     
    function QuickApp:requestLoop()
    local url = "http://".. self:getVariable("IPAddress")
    local query = "/?device=relay&name=Power2&command=get"
    url = url .. "" .. query
     
    self:debug("RequestLoop [url:", url, "]")
     
    -- it would be nice to move this code to sendCommand method. But it need some refactor :) for example someErrorCallback is needed
    self.httpClient:request(url,
    {
    options={
    method = "GET"
    },
    success = function (response)
    if (response.status >= 200 and response.status < 300) then
    self:debug("OK: " .. response.data)
    local jS = json.decode(response.data)["value"]
    if (jS == "off") then
    stat = "Lamp Off"
    self:updateProperty("value", false)
    elseif (jS == "on") then
    stat = "Lamp On"
    self:updateProperty("value", true)
    end
     
    self:debug(stat)
    self:updateView("status", "text", stat)
    end
    fibaro.setTimeout(self.pollingTime, function() self:requestLoop() end) -- looping part
    end,
    error = function (err)
    errorlog("Error: " ..err)
    fibaro.setTimeout(self.pollingTime, function() self:requestLoop() end) -- looping part
    end
    })
    end
     
    function QuickApp:onInit()
    self:debug("onInit")
    self.httpClient = net.HTTPClient()
    self.pollingTime = 3 * 1000 -- 3s
     
    self:requestLoop()
    end
     
    -- This 'LUA Code' is not looped automatically. If you need to loop some part of code (eg. some http requests) you need to do it yourself.
    -- To loop function in asynchronous environment you can do something like this:
     
    -- function loop()
    -- print("doing sth")
    -- fibaro.setTimeout(1000, function() loop() end)
    -- end
     
    -- In case of looping functions that are using http requests, you should use this 'looping' setTimeout in success/error callbacks (like in requestLoop method)

     

     

    but I get errors :-(

     

    Please login or register to see this attachment.

     

    Link to comment
    Share on other sites

    • 0
    On 2/12/2020 at 1:01 PM, jgab said:

    Just a reflection...

    I'm starting to come to the conclusion that one shouldn't add functions to the QuickApp object/class unless they are part of the device's "API"...

    The QuickApp class/object only have one predefined method 'onInit()'... the other methods you define on QuickApp are callbacks (UI elements and functions being available with  fibaro.call(<device>, <name>, ...). As such they are accessible from other devices/scenes or external API. The specific support/functionality for a device resides in the 'self' object (getVariable, updateView etc..) and is not exposed in the same way.

    So my point is that I don't think people should make a habit on adding all functions to QuickApp, but create "normal" Lua functions and "objects" that are kicked-off by a call from :onInit().

    But that will probably be part of the proper FQA documentation ;-) 

    So, I was partly not knowing what I was talking about. Functions on self are also "exposed" as external API functions. In theory it makes sense because self is an instance of the class (QuickApp in this case). In theory it's also a bit wonky to add functions to self (the instance) without properly extending the class - (but they add "instance variables" in their example)...  Here they could have made it in a way so that only the functions declared as part of the class, was exposed - and then add the getVariable etc to self at creation so they were not externally visible... well well.

    Please login or register to see this link.

    of function QuickApp:loop()... I'm not sure what I think of that function being accessible over the REST API ;-) 

    So, my rule will be to keep most of my functions outside the QuickApp class and self object...

    • Like 1
    Link to comment
    Share on other sites

    • 0

    Another method to loop a QuickApp

    Please login or register to see this code.

     

    Edited by AutoFrank
    Link to comment
    Share on other sites

    • 0
    23 hours ago, ptekien said:

    but I get errors

     @ptekien

     

    What code is at line 35  where it is crasHing for an unexpected character

    It won't run on my HC3 as I don't have that sonoff module

    Link to comment
    Share on other sites

    • 0
    32 minutes ago, AutoFrank said:

    Another method to loop a QuickApp

    Please login or register to see this code.

     

     

    I think what I was trying to say in my previous posts was that "internal" functions like a loop should not be exposed by defining them as class methods of QuickApp (or extensions of instance self)

    The loop in your example can be called as

    Please login or register to see this code.

    Granted they need the credentials to the HC3, but it doesn't really make sense.

    Classes are a way to scope functions, and the QuickApp class exposes all it's function externally or to other devices so one should take that into consideration...

    ...much better to use an ordinary Lua function for the loop.

    Link to comment
    Share on other sites

    • 0
    10 godzin temu, AutoFrank napisał:

     @ptekien

     

    What code is at line 35  where it is crasHing for an unexpected character

    It won't run on my HC3 as I don't have that sonoff module

     
    I paste the screen below
     

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    Someone figured out how to get rid of the 'onUIEvent' logs that are printed in the debug window when you press a UI element?

    Please login or register to see this code.

    The intrusive green boxes with "Action has been called" is not so hot to always have popping up either...

    Link to comment
    Share on other sites

    • 0
    1 hour ago, jgab said:

    The intrusive green boxes with "Action has been called" is not so hot to always have popping up either...

    Aka "green toaster messages". This has been reported by several users (to Fibaro through private bug tracker) as annoying. BTW I find them annoying too.

    Link to comment
    Share on other sites

    • 0
    5 hours ago, petergebruers said:

    Aka "green toaster messages". This has been reported by several users (to Fibaro through private bug tracker) as annoying. BTW I find them annoying too.

    Yes, and they add them in the lower left corner where they cover the debug output ?

    Link to comment
    Share on other sites

    • 0
    On 2/11/2020 at 6:38 PM, ptekien said:

    Does anyone know how to send a GET command with a url address in Quick apps to control another device via LAN? It is not possible to enter the IP address. In HC2 I sent:

     

     

     

    I'm interested in this, too. In HC2 I have VD's to control an ITach device (IR blaster) connected to the local network by Ethernet. In the VD I just entered the ITachs IP address and port number, and in the buttons I just entered a "sendir" command with the IR code for the different buttons.

    Link to comment
    Share on other sites

    • 0
    31 minutes ago, robw said:

     

    I'm interested in this, too. In HC2 I have VD's to control an ITach device (IR blaster) connected to the local network by Ethernet. In the VD I just entered the ITachs IP address and port number, and in the buttons I just entered a "sendir" command with the IR code for the different buttons.

    You use net.httpClient

     

    • Thanks 1
    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...