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 App for WLED Http Call


Question

Posted

I am trying to create a QuickApp for the new Home Center 3 for controling my WLED lighting which before I used a VD in HC2 copy below.

 

There is so much information on this forum going in all sorts of directions on how to achieve this relativly simple HTTP request. I am finding this very confusing as how to achive this. Only need to send out a HTTP call with no responce needed to switch on one of these Led strips.

 

I have created a QuickApp as a device controller and give it a series of buttons (on the left side of page) which I would like to be able to click and send a HTTP request to make the WLED light go On or Off, or change colour, Example of VD buttons from HC2 below

 

Toggle WLED light On or Off when pressed

 

Button Name:- Toggle

 

Required action on pressing button below:-

 

HTTP = Net.FHttp("192.168.1.16")
response, status, errorCode = HTTP:GET("/win&T=2")
if ( errorCode == 0 )
then
print("OK!")
end

 

Change colour pattern and effect when pressed (LAPD effect)

 

Button Name :- LAPD 

 

Required action on pressing button below:-

 

HTTP = Net.FHttp("192.168.1.16")
response, status, errorCode = HTTP:GET("/win&FX=38&FP=16")
if ( errorCode == 0 )
then
print("OK!")
end

 

 

Ultimately I would like to be able to activate these buttons from a scene at certain times of day, say nightime to switch on several WLED light systems throughout the house.

 

What I need is a start or example code for the Lua editor (on the right side of page). Finding it difficult to get started with this new system in HC3.

 

Any help would be appreciated. Like many have lots of time on my hands for testing now with the current global situation.

 

Keep safe everyone

 

Posted the above on different message tag but got no responce to help in making a QA for this so trying a different tag see if anyone can help with this.

 

Thanks, Graham

Please login or register to see this attachment.

Please login or register to see this attachment.

11 answers to this question

Recommended Posts

  • 0
  • Inquirer
  • Posted

    Anyone have idea on this ?

     

    Its one of the last things I need to setup on the new HC3 system that I had on the old HC2.

    • 0
    Posted

    Okay, so doing the HTTP and JSON stuff with WLED is the easy part...

     

    But... I have to admit... The current limitations of the Browser Interface and Mobile App interface drive me insane...

     

    A WLED device looks a bit like a mix of an RGBW module, and a dimmer, and a "thing" selecting presets, and another "thing" selecting effects like a "rainbow" or "breathe" effect.

     

    No matter what kind of GUI I try to make... It never quite "fits" or it does not work.

     

    I think the easiest approach is what you stared with, ie make a fully "custom" device but that does not work on your phone.

    • 0
  • Inquirer
  • Posted (edited)
    On 5/4/2020 at 2:14 PM, petergebruers said:

    Okay, so doing the HTTP and JSON stuff with WLED is the easy part...

     

    But... I have to admit... The current limitations of the Browser Interface and Mobile App interface drive me insane...

     

    A WLED device looks a bit like a mix of an RGBW module, and a dimmer, and a "thing" selecting presets, and another "thing" selecting effects like a "rainbow" or "breathe" effect.

     

    No matter what kind of GUI I try to make... It never quite "fits" or it does not work.

     

    I think the easiest approach is what you stared with, ie make a fully "custom" device but that does not work on your phone.

     

     

    @petergebruers, I am still having problems with the QA I wrote it sometimes connects, and sometimes get stuck with conection and blocks external HTTP requests.

     

    I am beginning to think this is going to be a long wait as the Firmware for the HC3 is still very green and mostly unusable until more options are opened up. There is going to be quite a few people feeling frustrated with HC3 not being up to speck until they get the firmware working. So many option still not available.

     

    As you said the HC3 mobile app has so many bugs and not working, the scene to QA not working with a lot of options.

     

    I am just going to have to keep the HC2 and HC3 running in parrallel until this is more mature.

     

    What I have now can only work from the control panel HC3 manual pressing the buttons, the mobile forget it until this is fixed, and scenes still not sure how to even start with this as has limits. Would be nice to have sliders, but for all of the possible effects and colours I think this would be far too complicated and only a few favorite buttons are needed.

     

    Here is what I have so far,

     

    --

    -- QuickApp created by Graham Parsons with software example taken from "Autofrank (Frank Smith) to control a Tasmota flashed switch"

    -- repurposed to use with WLED

    -- This is not a finshed product but a start for a QuickApp to control WLED modules over HTTP 

    --

     

    -- 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("/win&T=1", 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("/win&T=0", 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

     

    function QuickApp:LAPD()

        self:debug("binary switch LAPD")

        self:sendCommand("/win&FX=38&FP=16", function()

            -- this will happen on  success http 200 

            self:updateView("label", "text", "LAPD ON") -- 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

     

    function QuickApp:Orangery()

        self:debug("binary switch Orangery")

        self:sendCommand("/win&FX=39&FP=47", function()

            -- this will happen on  success http 200 

            self:updateView("label", "text", "Orangery ON") -- 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

     

    function QuickApp:Fire()

        self:debug("binary switch Fire")

        self:sendCommand("/win&FX=66&FP=35", function()

            -- this will happen on  success http 200 

            self:updateView("label", "text", "Fire ON") -- 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

     

    function QuickApp:ColourLoop()

        self:debug("binary switch Colour Loop")

        self:sendCommand("/win&FX=66&FP=35", function()

            -- this will happen on  success http 200 

            self:updateView("label", "text", "Colour Loop ON") -- 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

     

    function QuickApp:Candle()

        self:debug("binary switch Candle")

        self:sendCommand("/win&FX=88&FP=0", function()

            -- this will happen on  success http 200 

            self:updateView("label", "text", "Candle ON") -- 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

     

    function QuickApp:Lightning()

        self:debug("binary switch Lightning")

        self:sendCommand("/win&FX=88&FP=0", function()

            -- this will happen on  success http 200 

            self:updateView("label", "text", "Lightning ON") -- 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 = "/cm?cmnd=Status"

        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)

                    jS = json.decode(response.data)

                    if (jS.Status.Power) == 0 then

                        stat = "Lamp Off"

                        self:updateProperty("value", false)

                    elseif (jS.Status.Power) == 1 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)


     

    function QuickApp:uibtnon1OnReleased(event)

    self:turnOn()

    end

     

    function QuickApp:uibtnoff2OnReleased(event)

    self:turnOff()

    end

     

    function QuickApp:uibtnon3OnReleased(event)

    self:LAPD()

    end

     

    function QuickApp:uibtnon4OnReleased(event)

    self:Orangery()

    end

     

    function QuickApp:uibtnon5OnReleased(event)

    self:Fire()

    end

     

    function QuickApp:uibtnon6OnReleased(event)

    self:ColourLoop()

    end

     

    function QuickApp:uibtnon7OnReleased(event)

    self:Candle()

    end

     

    function QuickApp:uibtnon8OnReleased(event)

    self:Lightning()

    end

    Edited by Graham
    • Thanks 1
    • 0
    Posted

    Thanks for sharing and I do agree with most of what you say, but I kind of doubt whether the HC3 is the cause of the WLED http issues... I have a few FQA's doing http and I see no such issues. I have seen the WLED device crash when I was testing different JSON commands. I am not sure if it was the command itself, or maybe when you issue commands too fast, is causes my ESP to crash. This was running 0.9.1. I updated to WLED 0.10.0 yesterday and noticed revision history mentions "Reduced heap memory usage by 2k (improves stability)".

     

    For a better "user experience" I think we'll have to wait until both mobile app and HC3 BUI support more features.

     

    I have "parked" this project for now, I don't have any WLED device "in production" but I might reconsider implementing one later this year.

     

    • 0
  • Inquirer
  • Posted

    @petergebruers

     

    Thanks for having a look at this,

     

    I did notice that the polling time in example I modified was 3 sec, I have increased this to 10 sec as I think this was too much. I have updated the WLEDs to the latest version 0.10.0, but still does not respond sometimes after multiple button presses.

     

    I think this is another issue, as I have the Sonos QA running on HC3 and this keeps blocking my Sonos comunication and looses some rooms all together. Have to unplug and reboot the Sonos room to get it back in the network. This never happened for years while using Sonos VD on HC2 until I updated the HC3 and installed the Sonos QA.

     

    Going to leave this project until things imporove on the HC3 firmware side some month or year, as this is painfully slow at getting out updates.

    • 0
    Posted (edited)

    Thank you for reporting back. I need a http interface to control a Shelly Bulb (RGBW), it is a bit similar to WLED control. This bulb will be "motion controlled" so I will very likely find out when the http interface fails (because the motion sensor is reliable and I know when the bulb does not turn on, it is a scene or http issue). This does not help you directly but I might be able to reproduce your http issues - or maybe not ;)

     

    As famously discussed at the end of the movie Burn After Reading - What Did We Learn?

     

     

    Edited by petergebruers
    • 0
    Posted

    Hello,

    Is there any update on this topic?

    :)

    Cheers!

    • 0
    Posted

    I did start working on the WLED Quick App code posted here by Graham and got all my needs fulfilled for now. If there is more interest in collaborating, I can put it up on my GitHub. I really don't like the way Quick App code is being distributed in general.

    • 0
    Posted

    Follow the advice of Linus Torvalds: "Only wimps use tape backup. REAL men just upload their important stuff on ftp and let the rest of the world mirror it.” - now I am sure, in 2023 he would say "GitHub" instead of "ftp".

    • Like 2
    • 0
    Posted

    I really have to get used to the way of working in the home center community (compared to Home Assistant for sure), but we'll get there 😉

    • Like 1
    • 0
    Posted
    On 1/27/2023 at 12:31 AM, rliessum said:

    I did start working on the WLED Quick App code posted here by Graham and got all my needs fulfilled for now. If there is more interest in collaborating, I can put it up on my GitHub. I really don't like the way Quick App code is being distributed in general.

    Hi @rliessum, did you manage to get the WLED quick app working? I recently built one light with WLED control and wanted to play around with the integration into Fibaro before deciding on building more WLED lights.

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