Homey Community Forum

APi Homey no longer working


#1

Hi. I am using a Fibaro HomeCenter to send commands to Homey using the Homey API.

After upgrading Homey to version 2 (what I shouldn’t have done) the API is not longer working.
Anyone who know how to solve it ?

I using the below script:

–[[
%% properties
%% events
%% globals
SC_Homey_Command
–]]

:information_source: Initialisation of user settings (change if necessary)

local globVarCommand = ‘SC_Homey_Command’; – Name of global variable to read command
local globVarValue = ‘SC_Homey_Value’; – Name of global variable to read command value
local homeyToken = ‘’; – Not used yet
local homeyIp = ‘192.168.3.5’; – IP-address of your Athom Homey

local debug = true;

– Funtions (do not change)

local function log(str) if debug then fibaro:debug(’’…str…’’); end; end
local function errorlog(str) fibaro:debug(’’…str…’’); end

– Code (do not change)

local selfHttp = net.HTTPClient({timeout=5000});

if (tonumber(fibaro:getGlobalValue(globVarCommand)) == 0) then fibaro:abort();
end
local command = fibaro:getGlobalValue(globVarCommand);
local command = string.gsub(command,’%s’,’%%20’); – Replace with %20
local value = fibaro:getGlobalValue(globVarValue);
local value = string.gsub((value), ‘%s’, ‘%%20’); – Replace with %20
local value = string.gsub((value),’?’,’%%3F’); – Replace ? with %3F

local apiURL = ‘http://’…homeyIp…’/api/app/com.internet/’…tostring(command)…’/’…value;
if debug then log(apiURL) end;

selfHttp:request(apiURL, {options={headers = selfHttp.controlHeaders, data = requestBody, method = ‘GET’,timeout = 5000},
success = function(status)
local result = json.decode(status.data);
if result.status == 200 then
if debug then log(‘OK’) end;
else
errorlog(‘failed’);
if debug then log(status.data) end;
end
end,
error = function(error)
errorlog(“ERROR”);
if debug then log(error) end;
end
})
– Reset the global command variable to 0 and global value variable to empty
fibaro:setGlobal(globVarCommand, ‘0’);
fibaro:setGlobal(globVarValue, ‘’);

Thanks for the help.


#2

Not a developer here but just the IPadress is not gonna work in 2.0

https://<cloudid>.connect.athom.com/api/app/

Is what is working for 2.0


#3

But what if the cloud isn’t working? Or the internet connection is gone?


#4

Hi. Thank you so much. It’s working now.