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

using result from function in earlier function


Symbiot78

Question

hi
 
at the end of my QA I have a function(function 1) that grabs info from a selected shade. The function works fine.
in the beginning I have another function (function 2) that calls the below function but I want to grab the result and use it in function 1. I've tried all sorts of ways of calling the function and getting the data from func 1 to func 2 but I can't seem to figure it out..
Could some one point out my mistake?
 
 
--function 1
function QuickApp:update_slider()
net.HTTPClient():request(url, {
    options={
      headers = {
        ['Content-Type'] = 'application/json',
      },
      method = 'GET',
    },
success = function(response) 
            --print(response.status)
            --print(response.data)
            bob = json.decode(response.data)
            shader1 = bob.shade.positions.position1
            fibaro.debug("QUICKAPP368",shader1)
            end,
    error = function(message)
            print("error:", message)
    end
})
end
 
--function 2
function QuickApp:button3_1_pressed()
self:updateView("label_1""text"" Alkove Valgt")
selected_button = "button3_1"
shade = blind_id_1
url = "http://"..powerview_ip.."/api/shades/"..shade
self.update_slider(shader1) 
fibaro.debug("QUICKAPP368",shader1)
self:updateView("slider_1","value",tostring(shader1))
end
 
 
 
Link to comment
Share on other sites

18 answers to this question

Recommended Posts

  • 0
  • Inquirer
  • ok.. so I tried clicking the button_1 2 times.. and the 2nd time it actually updates my values..

    what the ... ?

     

    I must be doing something wrong.. but what?

     

    I have retried it a few times.. and every time.. first click does nothing.. 2nd click updates my slider..?

    Link to comment
    Share on other sites

    • 0
    28 minutes ago, Symbiot78 said:

    ok.. so I tried clicking the button_1 2 times.. and the 2nd time it actually updates my values..

    what the ... ?

     

    I must be doing something wrong.. but what?

     

    I have retried it a few times.. and every time.. first click does nothing.. 2nd click updates my slider..?

    HTTPClient is asynchronous - please see 

     

    (Another weekly reason

    Please login or register to see this link.

    . In this case it would have been no problem if the UIEvent handler was suspended until the http requests returned. Other setTimeouts and UIEvent/actionHandlers could still be allowed to run)

     

    You need to do something like this

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @jgab thank you. I wasn't aware of that.

     

    would you mind terribly explaining what you're doing here:

     

    Please login or register to see this code.

    and here:

     

    Please login or register to see this code.

    specifically the ,cont & the ,update

     

    you have 2 expressions in the (). How does that work?

     

    let me try my understanding of it:

    function2 you added this:

    Please login or register to see this code.

     

    so if I wanted to run another http request in the same function but this time a GET.. how would I do that?

     

    http://10.20.10.17/api/shades/40999?refresh=true

     

    Link to comment
    Share on other sites

    • 0
    33 minutes ago, Symbiot78 said:

    @jgab thank you. I wasn't aware of that.

     

    would you mind terribly explaining what you're doing here:

     

    Please login or register to see this code.

    and here:

     

    Please login or register to see this code.

    specifically the ,cont & the ,update

     

    you have 2 expressions in the (). How does that work?

     

    let me try my understanding of it:

    function2 you added this:

    Please login or register to see this code.

     

    so if I wanted to run another http request in the same function but this time a GET.. how would I do that?

     

    http://10.20.10.17/api/shades/40999?refresh=true

     

     

    So you understand that net.HTTPClient() is asynchronous. 

    That means that the net.HTTPClient():request(...) returns immediately and later when the result gets back from the http request it will call your success handler, or error handler if something went wrong.

     

    This means that you will always get the results (the success handler being called) after your QuickApp:button3_1_pressed() is done.

     

    (It turns out that in Lua, only one asynchronous function can run at the time, so net.HTTPClient() has to wait until QuickApp:button3_1_pressed() is done before it can call the success handler)

     

    Anyway, what we do is that we define a local function update that we send to our QuickApp:update_slider(url,cont) and that when the http request is ready it will call the function with the result. (I call the parameter 'cont' as in "continue", continue with this when you are ready)

    The update function then has the value and can update labels or what not.

    I also send the url to QuickApp:update_slider(url,cont) thinking that it can be reused for other tasks, but you should really restructuring the code a bit then. Now QuickApp:update_slider(...) is hard-coded for shader values.

     

    You could do like this:

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • hi @jgab

     

    thanks a million. I truly appreciate your time helping!

     

    I tried your addition (changed it to match) but am getting an error..

     

    self:httpGET("http://"..powerview_ip.."/api/shades/"..shade.."?refresh=true")
     
    throws an error:
    ./include/main.lua:107: attempt to call a nil value (method 'httpGET')
     
    I tried using the hardcoded IP etc. but same error. as I understand it it's saying httpGET is empty?
    Link to comment
    Share on other sites

    • 0

    The error message is saying that it tries to call

    Please login or register to see this code.

    but it's not defined. Did you leave it out or change name of it?

    If you still have issues you can post the whole QA code so we can have look at it. 

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi @jgab

     

    Here's the whole thing.. but it's probably.. or rather.. it IS a complete mess. 

    This is my first and it's just an amalgamation of google-coding and asking... mostly :)

     

     

    -- Device Controller is a little more advanced than other types. 
    -- It can create child devices, so it can be used for handling multiple physical devices.
    -- E.g. when connecting to a hub, some cloud service or just when you want to represent a single physical device as multiple endpoints.
    -- 
    -- Basic knowledge of object-oriented programming (oop) is required. 
    -- Learn more about oop: https://en.wikipedia.org/wiki/Object-oriented_programming 
    -- Learn more about managing child devices: https://manuals.fibaro.com/home-center-3-quick-apps/
     
    function QuickApp:onInit()
        self:debug("QuickApp:onInit")
        --selected_button = ""
        self.selected_button = ""
     
        -- local variables from user
        powerview_ip = self:getVariable("IP")
        blind_name_1 = ""
        blind_name_2 = ""
        blind_name_3 = ""
        blind_id_1 = ""
        blind_id_2 = ""
        blind_id_3 = ""
        shade_id = ""    
        url = ""
        shader1 = ""
        update_slider = "" 
    -------------------- SLIDER -----------
        self:updateView("slider_1","min","0"-- set absolute min of slider / ref @jgab
        self:updateView("slider_1","max""65535"--set absolute max of slider / ref @jgab
        self:updateView("slider_1""value""32500"--set slider at 21 at start
        self:updateView("slider_1""step""5000")  --step 0.5 at the time
     
    --------------------------------------
     
        
    -- Update Button Names
     
    self:updateView("button3_1""text"self:getVariable("blind_name_1"))
    self:updateView("button3_2""text"self:getVariable("blind_name_2"))
    self:updateView("button3_3""text"self:getVariable("blind_name_3"))
     
    -- Update Button/Shade ID
    blind_id_1 = self:getVariable("blind_id_1")
    blind_id_2 = self:getVariable("blind_id_2")
    blind_id_3 = self:getVariable("blind_id_3")


     
        -- Setup classes for child devices.
        -- Here you can assign how child instances will be created.
        -- If type is not defined, QuickAppChild will be used.
        self:initChildDevices({
            ["com.fibaro.binarySwitch"] = MyBinarySwitch,
        })
     
        -- Print all child devices.
        self:debug("Child devices:")
        for id,device in pairs(self.childDevices) do
            self:debug("[", id, "]", device.name, ", type of: ", device.type)
        end
    end
     
    -- Sample method to create a new child. It can be used in a button. 
    function QuickApp:createChild()
        local child = self:createChildDevice({
            name = "child",
            type = "com.fibaro.binarySwitch",
        }, MyBinarySwitch)
     
        self:trace("Child device created: ", child.id)
    end
     
    -- Sample class for handling your binary switch logic. You can create as many classes as you need.
    -- Each device type you create should have its class which inherits from the QuickAppChild type.
    class 'MyBinarySwitch' (QuickAppChild)
     
    -- __init is a constructor for this class. All new classes must have it.
    function MyBinarySwitch:__init(device)
        -- You should not insert code before QuickAppChild.__init. 
        QuickAppChild.__init(self, device) 
     
        self:debug("MyBinarySwitch init")   
    end
     
    function MyBinarySwitch:turnOn()
        self:debug("child", self.id, "turned on")
        self:updateProperty("value"true)
    end
     
    function MyBinarySwitch:turnOff()
        self:debug("child", self.id, "turned off")
        self:updateProperty("value"false)
    end
     
    -- press button 3_1
    function QuickApp:button3_1_pressed()
      self:updateView("label_1""text"" Alkove Valgt"-- update label with selected blind
      selected_button = "button3_1" -- set selected button to button3_1 for use with open/close function
      shade = blind_id_1 -- set shade to match blind_id_1 from variables input by user
      local function update(shader) -- local function only present in the button3_1_pressed function (local) - uses the function 'update' which is located further down in the script.
      fibaro.debug("QUICKAPP368",shader)
     
         self:updateView("slider_1","value",tostring(shader)) -- update slider_1 with the value in 'shader'
      end
      self:update_slider("http://"..powerview_ip.."/api/shades/"..shade, update) 
    --    self:httpGET("http://"..powerview_ip.."/api/shades/"..shade.."?refresh=true") -- was it this you wanted to add here?
        --self:httpGET("http://10.20.10.17/api/shades/40999?refresh=true") -- was it this you wanted to add here?
      
    end
     
    function QuickApp:button3_2_pressed()
    self:updateView("label_1""text""New Yorker Valgt")
    selected_button = "button3_2"
    shade = blind_id_2
    fibaro.debug("QUICKAPP368",selected_button)
    end
     
    function QuickApp:button3_3_pressed()
    self:updateView("label_1""text""Stue Valgt")
    selected_button = "button3_1"
    shade = blind_id_3
    fibaro.debug("QUICKAPP368",selected_button)
    end
     
    ----- Åben -----
    function QuickApp:button2_1_pressed()
    self:updateView("label_1""text""Åbner")
        -- alkove
        local url = "http://"..powerview_ip.."/api/shades/"..shade
        fibaro.debug("QUICKAPP368",url)
        
        local postdata = {
        ["shade"] = {
        --["motion"] = "jog",
        ["positions"] = {
        ["posKind1"] = "1",
        ["position1"] = 65535
                }
            }
        }
        net.HTTPClient():request(url, {
        options={
        headers = {
        ['Content-Type'] = 'application/json',
        },
        data = json.encode(postdata),
        method = 'PUT',
        },
        success = function(response)
        print(response.status)
        print(response.data)
        end,
        error = function(message)
        print("error:", message)
        end
        })
        
    end
     
    ----- Luk ------
    function QuickApp:button2_2_pressed()
    self:updateView("label_1""text""Lukker")
        -- alkove
        local url = "http://"..powerview_ip.."/api/shades/"..shade
        fibaro.debug("QUICKAPP368",url)
        local postdata = {
        ["shade"] = {
        --["motion"] = "jog",
        ["positions"] = {
        ["posKind1"] = "1",
        ["position1"] = 0
                }
            }
        }
        net.HTTPClient():request(url, {
        options={
        headers = {
        ['Content-Type'] = 'application/json',
        },
        data = json.encode(postdata),
        method = 'PUT',
        },
        success = function(response)
        print(response.status)
        print(response.data)
        end,
        error = function(message)
        print("error:", message)
        end
        })
       
    end
     
    -------STOP -----
     
    function QuickApp:button_1_pressed()
    selected_button = "button_1"
    fibaro.debug("QUICKAPP368","STOP")
        local postdata = {
        ["shade"] = {
        ["motion"] = "stop",
            }
        }
        net.HTTPClient():request(url, {
        options={
        headers = {
        ['Content-Type'] = 'application/json',
        },
        data = json.encode(postdata),
        method = 'PUT',
        },
        success = function(response)
        print(response.status)
        print(response.data)
        end,
        error = function(message)
        print("error:", message)
        end
        })
    ----------------
    end
     
    function QuickApp:update_slider(url,cont)
      net.HTTPClient():request(url, {
        options={
          headers = {
            ['Content-Type'] = 'application/json',
          },
          method = 'GET',
        },
      success = function(response) 
                --print(response.status)
                --print(response.data)
                local bob = json.decode(response.data)
                local shader1 = bob.shade.positions.position1
    --            fibaro.debug("QUICKAPP368",shader1)
                cont(shader1)
                end,
        error = function(message)
                print("error:", message)
        end
      })
    end
     
    --
    function QuickApp:slider_1_changed()
    -- https://manuals.fibaro.com/home-center-3-quick-apps/  <--- står om slider change
     
    end
     
    function QuickApp:update_pos(url,cont1)
      net.HTTPClient():request(url, {
        options={
          headers = {
            ['Content-Type'] = 'application/json',
          },
          method = 'GET',
        },
      success = function(response) 
                --print(response.status)
                --print(response.data)
                local bob = json.decode(response.data)
                local shader1 = bob.shade.positions.position1
                fibaro.debug("QUICKAPP368",shader1)
                cont1(shader1)
                end,
        error = function(message)
                print("error:", message)
        end
      })
    end

    there's probably a lot that can be done better and should.. but it works...so far.. I've broken it many times trying to figure out stuff.

    Link to comment
    Share on other sites

    • 0

    So you didn't implement self:httpGET and that's why it complained.

    My thinking is that you have a generic http function (QuickApp:httpREQ in this case) and you use that for all http requests you need to do from various buttons.

    The httpREQ function has a continuation function where you specify what should be done when the result is returned from the http requests. Like updating labels, sliders, logging etc.

     

    • There is  no need for QuickApp:update_pos and QuickApp:update_slider anymore as you update the slider in the continuation function you provide to QuickApp:httpREQ
    • httpREQ now also takes http method and optional data in case the method is a POST or PUT.
    • The continuation now gets both the status and data from the successful request (for logging).
    • In the PUT examples I define the cont function directly as the 4th parameter instead of first delaying the cont function as a local function - like in the GET example.
    • Both ways work equally good - if the function is small I like to declare it "inline"
    • In QuickApp:button_1_pressed() the url is missing
    • Be careful with global variables and declare/list them in the beginning so you know which ones you have. Don't introduce them in the code by just assigning them (like ex 'shade'). Do you need 'shader1' etc.

     

    The structure of your QA then becomes like below.

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @jgab - damn... there's a lot of changes and useful info :)

    the httpGET function is gold.. I never could figure out why I should have so many lines of http function stuff clogging up the QA.

     

     

    I tried adding your code directly and replace my own. 

     

    the app is now very sluggish.. clicking the 3_1 button is fast.. but clicking open either doesn't work or responds only after a long time. also it doesn't grab the 'shade' value.. and thus fails ...maybe because it isn't declared under init?

     

    the 'STOP' isn't missing the url. I reused the url parameter from 3_1_pressed as I had it declared as a global variable.. is this not best practice to do?

    Link to comment
    Share on other sites

    • 0
    16 minutes ago, Symbiot78 said:

    @jgab - damn... there's a lot of changes and useful info :)

    the httpGET function is gold.. I never could figure out why I should have so many lines of http function stuff clogging up the QA.

     

     

    I tried adding your code directly and replace my own. 

     

    the app is now very sluggish.. clicking the 3_1 button is fast.. but clicking open either doesn't work or responds only after a long time. also it doesn't grab the 'shade' value.. and thus fails ...maybe because it isn't declared under init?

     

    open is the button2_1_pressed ?

    It doesn't grab the shader value. The cont function only logs the status/data. If you need to do something with the result like updating shade value you need to look at the data in the cont function and update the shade, like in 3_1

     

     

    16 minutes ago, Symbiot78 said:

     

    the 'STOP' isn't missing the url. I reused the url parameter from 3_1_pressed as I had it declared as a global variable.. is this not best practice to do?

    No, it's very confusing as it is impossible to understand where the url comes from. I believed it was missing.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • open is 2_1_pressed yes.

     

    I did this:

    -- press button 3_1 function QuickApp:button3_1_pressed() self:updateView("label_1", "text", " Alkove Valgt") -- update label with selected blind selected_button = "button3_1" -- set selected button to button3_1 for use with open/close function shade = blind_id_1 -- set shade to match blind_id_1 from variables input by user local function update(data) -- local function only present in the button3_1_pressed function (local) - uses the function 'update' which is located further down in the script.

     

     

    and then this but maybe it's not getting the 'shade' from buttom3_1_pressed because of 'local' in 2_1_pressed ?:

     

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • here's a small video to show the results.

     

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • as far as I can tell it's this line:

     

    if cont then cont(response.status,response.data) end

     

    That stops the code.  I tried placing a fibaro.debug right above and it works.

    I placed one below and nothing happens.

    Link to comment
    Share on other sites

    • 0
    13 minutes ago, Symbiot78 said:

    as far as I can tell it's this line:

     

    if cont then cont(response.status,response.data) end

     

    That stops the code.  I tried placing a fibaro.debug right above and it works.

    I placed one below and nothing happens.

     

    The reason it stops is because the cont function provided has an error in it. Unfortunately is doesn't (always) show up in the debugger.

    Could you change the QuickApp:httpREQ function to this

    Please login or register to see this code.

    and you may see the error....

     

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • directly replacing the code with the above throws this as soon as I press button3_1

    line 55 is 

     

      -- If type is not defined, QuickAppChild will be used.
        self:initChildDevices({
            ["com.fibaro.binarySwitch"] = MyBinarySwitch,    ---- <-------
        })

     

    /usr/share/lua/5.3/json/util.lua:55: bad argument #1 to 'for iterator' (table expected, got number)

    Link to comment
    Share on other sites

    • 0
    1 hour ago, Symbiot78 said:

    directly replacing the code with the above throws this as soon as I press button3_1

    line 55 is 

     

      -- If type is not defined, QuickAppChild will be used.
        self:initChildDevices({
            ["com.fibaro.binarySwitch"] = MyBinarySwitch,    ---- <-------
        })

     

    /usr/share/lua/5.3/json/util.lua:55: bad argument #1 to 'for iterator' (table expected, got number)

    No, that's line 55 inside the json library :-)

    So it's probably a json encode/decode that blows up.

    Add this to the beginning of your QA code (top-level outside onInit())

    Please login or register to see this code.

    and you will hopefully get an error that points out the right line in your code

    Edited by jgab
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi @jgab

     

    so.. adding that code didn't do much difference. Can't see that it displays anything new..

     

    this is the error:

     

    ./include/main.lua:140: /usr/share/lua/5.3/json/util.lua:55: bad argument #1 to 'for iterator' (table expected, got number)

     

    this is the code I am using:

     

     

    -- Device Controller is a little more advanced than other types. 
    -- It can create child devices, so it can be used for handling multiple physical devices.
    -- E.g. when connecting to a hub, some cloud service or just when you want to represent a single physical device as multiple endpoints.
    -- 
    -- Basic knowledge of object-oriented programming (oop) is required. 
    -- Learn more about oop: https://en.wikipedia.org/wiki/Object-oriented_programming 
    -- Learn more about managing child devices: https://manuals.fibaro.com/home-center-3-quick-apps/
     
    -- global variables from user
    powerview_ip = ""
    blind_name_1 = ""
    blind_name_2 = ""
    blind_name_3 = ""
    blind_id_1 = ""
    blind_id_2 = ""
    blind_id_3 = ""
    shade_id = ""    
    url = ""
    shader1 = ""
    shade = ""
    update_slider = ""
     
    -------------
     
     do
        local encode,decode=json.encode,json.decode
        function json.decode(...)
          local stat,res = pcall(decode,...)
          if not stat then error(res,2else return res end
        end
        function json.encode(...)
          local stat,res = pcall(encode,...)
          if not stat then error(res,2else return res end
        end
    end
     
    ------------
     
    function QuickApp:onInit()
      self:debug("QuickApp:onInit")
      --selected_button = ""
      self.selected_button = ""
     
      powerview_ip = self:getVariable("IP")
     
    -------------------- SLIDER -----------
      self:updateView("slider_1","min","0"-- set absolute min of slider / ref @jgab
      self:updateView("slider_1","max""65535"--set absolute max of slider / ref @jgab
      self:updateView("slider_1""value""32500"--set slider at 21 at start
      self:updateView("slider_1""step""5000")  --step 0.5 at the time
     
    --------------------------------------
     
    -- Update Button Names
     
      self:updateView("button3_1""text"self:getVariable("blind_name_1"))
      self:updateView("button3_2""text"self:getVariable("blind_name_2"))
      self:updateView("button3_3""text"self:getVariable("blind_name_3"))
     
    -- Update Button/Shade ID
      blind_id_1 = self:getVariable("blind_id_1")
      blind_id_2 = self:getVariable("blind_id_2")
      blind_id_3 = self:getVariable("blind_id_3")


     
      -- Setup classes for child devices.
      -- Here you can assign how child instances will be created.
      -- If type is not defined, QuickAppChild will be used.
      self:initChildDevices({
          ["com.fibaro.binarySwitch"] = MyBinarySwitch,
        })
     
      -- Print all child devices.
      self:debug("Child devices:")
      for id,device in pairs(self.childDevices) do
        self:debug("[", id, "]", device.name, ", type of: ", device.type)
      end
    end
     
    -- Sample method to create a new child. It can be used in a button. 
    function QuickApp:createChild()
      local child = self:createChildDevice({
          name = "child",
          type = "com.fibaro.binarySwitch",
          }, MyBinarySwitch)
     
      self:trace("Child device created: ", child.id)
    end
     
    -- Sample class for handling your binary switch logic. You can create as many classes as you need.
    -- Each device type you create should have its class which inherits from the QuickAppChild type.
    class 'MyBinarySwitch' (QuickAppChild)
     
    -- __init is a constructor for this class. All new classes must have it.
    function MyBinarySwitch:__init(device)
      -- You should not insert code before QuickAppChild.__init. 
      QuickAppChild.__init(self, device) 
     
      self:debug("MyBinarySwitch init")   
    end
     
    function MyBinarySwitch:turnOn()
      self:debug("child", self.id, "turned on")
      self:updateProperty("value"true)
    end
     
    function MyBinarySwitch:turnOff()
      self:debug("child", self.id, "turned off")
      self:updateProperty("value"false)
    end
     
    function QuickApp:httpREQ(method,url,data,cont) -- generic HTTP function
      net.HTTPClient():request(url, {
          options={
            headers = {
              ['Content-Type'] = 'application/json',
            },
            method = method,
            data = data and json.encode(data) or nil
          },
          success = function(response)
            if cont then 
              local stat,res = pcall(cont,response.status,response.data)
              if not stat then self:error(res) end
            end
          end,
          error = function(message)
            self:error("error:", message)
          end
        })
    end
    -- press button 3_1
    function QuickApp:button3_1_pressed()
      self:updateView("label_1""text"" Alkove Valgt"-- update label with selected blind
      selected_button = "button3_1" -- set selected button to button3_1 for use with open/close function
      shade = blind_id_1 -- set shade to match blind_id_1 from variables input by user
      local function update(data) -- local function only present in the button3_1_pressed function (local) - uses the function 'update' which is located further down in the script.
        local bob = json.decode(status,data)
        local shader = bob.shade.positions.position1
        self:debug("button3_1_pressed","Shader:",shader)
        self:updateView("slider_1","value",tostring(shader))
      end
      self:httpREQ("GET","http://"..powerview_ip.."/api/shades/"..shade, nil, update) 
      self:httpREQ("GET","http://10.20.10.17/api/shades/40999?refresh=true"-- was it this you wanted to add here? Does it need a continuation function to do something with the result?
    end
     
    function QuickApp:button3_2_pressed()
      self:updateView("label_1""text""New Yorker Valgt")
      selected_button = "button3_2"
      shade = blind_id_2
      self:debug(selected_button)
    end
     
    function QuickApp:button3_3_pressed()
      self:updateView("label_1""text""Stue Valgt")
      selected_button = "button3_1"
      shade = blind_id_3
      self:debug(selected_button)
    end
     
    ----- Åben -----
    function QuickApp:button2_1_pressed()
      self:updateView("label_1""text""Åbner"-- alkove
      local url = "http://"..powerview_ip.."/api/shades/"..shade
      self:debug("button2_1_pressed","url",url)
     
      self:httpREQ("PUT",url,{
          ["shade"] = {
            --["motion"] = "jog",
            ["positions"] = {
              ["posKind1"] = "1",
              ["position1"] = 65535
            }
          }
        },
        function(status,data) -- cont function, this will just log the result
          self:debug("button2_1_pressed","Status:",status)
          self:debug("button2_1_pressed","Data:",data)
        end)
    end
     
    ----- Luk ------
    function QuickApp:button2_2_pressed()
      self:updateView("label_1""text""Lukker"-- alkove
      local url = "http://"..powerview_ip.."/api/shades/"..shade
      self:debug("button2_2_pressed","url",url)
      self:httpREQ("PUT",url,{
          ["shade"] = {
            --["motion"] = "jog",
            ["positions"] = {
              ["posKind1"] = "1",
              ["position1"] = 0
            }
          }
        },
        function(status,data) -- cont function, this will just log the result
          self:debug("button2_2_pressed","Status:",status)
          self:debug("button2_2_pressed","Data:",data)
        end)
    end
     
    -------STOP -----
     
    function QuickApp:button_1_pressed()
      selected_button = "button_1"
      --local url = ????
      self:debug("button_1_pressed","STOP")
     
      self:httpREQ("PUT",url,{
          ["shade"] = {
            ["motion"] = "stop",
          }
        },
        function(status,data) -- cont function, this will just log the result
          self:debug("button_1_pressed","Status:",status)
          self:debug("button_1_pressed","Data:",data)
        end)
    ----------------
    end
     
    --
    function QuickApp:slider_1_changed()
    -- https://manuals.fibaro.com/home-center-3-quick-apps/  <--- står om slider change
     
    end

     

     

    Link to comment
    Share on other sites

    • 0

    It's line 140 that is the problem

    ./include/main.lua:140

    and it was an error I did when I hurried the coding... the parameters ended up in the wrong functions

    Should be

    Please login or register to see this code.

     

    Edited by jgab
    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...