This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

velux kfl-200
#1
hello,
is there someone who already dealed with this interface with "hidden" ip api ?


I found someone who made a script:


Code:
--[[
%% properties
%% events
%% globals
--]]

-- les variables globales ci-dessous sont initialisées avec des valeurs par défaut
-- ces valeurs seront normalement écrasées par le passage de paramètres lors de l'appel de la scène.

local VeluxDebug = true
local programme = "2"
local password = "xxxYYYzzz"
local KLF_ip = "192.168.yyy.zzz"


local params = fibaro:args()


if (params) then
    for k, v in ipairs(params) do
       if (v.programme) then
           programme = v.programme
       end
       if (v.adresseIP) then
           KLF_ip = v.adresseIP
       end
       if (v.password) then
            password = v.password
         end
    end
end

local urlLogin = 'http://'.. KLF_ip .. '/api/v1/auth'
local urlLogout = 'http://'.. KLF_ip .. '/api/v1/auth'
local urlScenes = 'http://'.. KLF_ip .. '/api/v1/scenes'
local datasLogin = '{"action":"login","params":{"password":"'.. password .. '"}}'
local datasLogout = '{"action":"logout","params":{}}'
local datasAction = '{"action":"run","params":{"id":"' ..programme ..'"}}'

if (VeluxDebug) then
    fibaro:debug("Démarrage de la scène avec les paramètres suivants")
    fibaro:debug("adresse IP = " .. KLF_ip)
    fibaro:debug("Password = " .. password)
    fibaro:debug("Programme = " .. programme)
   fibaro:debug(datasAction)
end



local klf = net.HTTPClient()

klf:request(urlLogin , {
   success = function(response)
        if tonumber(response.status)  == 200 then
              if (VeluxDebug) then
                fibaro:debug("Call for LOGON successfull")
                fibaro:debug("Valeur de response")
                fibaro:debug(json.encode(response))
           end
               
            -- récupération du token
            local temp = json.encode(response)
            local token = temp:match('\\\"token\\\":\\\"(.+)\\\",\\\"result')
            token = string.gsub(token, '\\', '')
              if (VeluxDebug) then
                fibaro:debug("Valeur du token : "..token)
            end
            
               klf:request(urlScenes, {
                      success = function(response)
                          if tonumber(response.status) == 200 then
                              if (VeluxDebug) then
                            fibaro:debug("Call for ACTION successful")
                            fibaro:debug("response\n")
                            fibaro:debug(json.encode(response))
                              end
                       klf:request(urlLogout , {
                           success = function(response)
                               if tonumber (response.status) == 200 then
                                   if (VeluxDebug) then
                                        fibaro:debug("Call for LOGOUT successful")
                                       fibaro:debug("response\n")
                                       fibaro:debug(json.encode(response))
                                       -- fibaro:debug("response.data\n")
                                         -- fibaro:debug(response.data)
                                     end
                                 else
                                       if (VeluxDebug)then
                                        fibaro:debug("LOGOUT Failed : Status =" .. response.status)      
                                      end
                                 end
                           end,
                           error = function(err)
                                 print ("Erreur de LOGOUT")
                               print('error = ' .. err)
                           end,
                           options = {
                               method = 'POST',
                               headers = {
                                      ["content-type"] = 'application/json, charset=utf-8',
                                      ["Authorization"] = "Bearer "..token,
                                   ["Connection"] = 'close',
                                  },
                               data = datasLogout
                           }
                        })
                    else
                           if (VeluxDebug)then
                            fibaro:debug("RUN ACTION Failed : Status =" .. response.status)      
                          end
                    end
               end,
                 error = function(err)
                   print("Erreur lors du RUN ACTION")
                   print('error =' ..err)
               end,
                 options = {
                      method = 'POST',
                      headers = {
                          ["content-type"] = 'application/json, charset=utf-8',
                       ["content-length"] = "34",
                       ["Authorization"] = "Bearer "..token,
                       ["Connection"] = 'Keep-Alive',
                      },
                   data = datasAction
               }
            })                            
          else
              if (VeluxDebug)then
                fibaro:debug("Login Failed : Status =" .. response.status)      
              end
          end           
    end,
    error = function(err)
        print ("Erreur lors du LOGIN")
       print('error = ' .. err)
    end,
    options = {
           method = 'POST',
       headers = {
            ["content-type"] = 'application/json, charset=utf-8',
           ["connection"] = 'close',
       },
       data = datasLogin
    }
})
-----------
FRANCE SMARTHOME & SMARTBUILDING INTEGRATION
SE ECO EXPERT
Reply


Messages In This Thread
velux kfl-200 - by domotiqa - 19.09.2018, 16:30
RE: velux kfl-200 - by admin - 01.10.2018, 06:22
RE: velux kfl-200 - by domotiqa - 11.02.2019, 14:17
RE: velux kfl-200 - by admin - 13.02.2019, 06:33
RE: velux kfl-200 - by domotiqa - 13.02.2019, 07:41
RE: velux kfl-200 - by MichelDeLigne - 03.04.2019, 20:13

Forum Jump: