Oui effectivement j'ai dû inverser, BLEU/ROUGE et les horaires à force de changer dans tous les sens. Du coup j'ai simplifié mon code avec if...then...else..then par mieux pour autant. (même en changeant les horaires)
Effectivement, je vais m'y mettre à l'indentation, ça sera plus lisible, mais mon problème se situe peut-être dans la compréhension des blocs. (et oui je suis pas un pro du dev)
Ca n'a pas changé mise à part qu'il m'affiche bien ROUGE alors que je devrait être bleu vu qu'il est plus de 19H00.
Merci de votre aide,,,, au pire je vais me pallucher la doc compléte...
--[[
%% autostart
%% properties
%% weather
%% events
%% globals
--]]
----------------------
local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
setTimeout(tempFunc, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
tempFunc()
else
end
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if ( startSource["type"] == "other") then
fibaro:getGlobal("TARIF_EDF");
fibaro:debug("on est ici get global EDF");
end
if ( ( (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "07", "00")) or tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "19", "00"))) and (math.floor(os.time()/60)-math.floor(1530738000/60))%1 == 0 )
)
then
fibaro:setGlobal("TARIF_EDF", "BLEU");
fibaro:debug('on est bleu');
local url = 'http://127.0.0.1:11111/api/scenes'
local function putMethod(requestUrl, successCallback, errorCallback)
local http = net.HTTPClient()
http:request(requestUrl, {
options = {
method = 'PUT',
data = message
},
success = successCallback,
error = errorCallback
})
end
message = '{"id": 443, "iconID": 1009}' -- this scene id = 443 and new icon id = 1009 BLEU
putMethod(url,
function(resp)
print('Status de la fonction HTTP PUT BLEU: ' .. resp.status)
end,
function(err)
print('error' .. err)
end
)
else
fibaro:setGlobal("TARIF_EDF", "ROUGE");
fibaro:debug("la on est rouge");
fibaro:setGlobal("TARIF_EDF", "ROUGE");
local url = 'http://127.0.0.1:11111/api/scenes'
local function putMethod(requestUrl, successCallback, errorCallback)
local http = net.HTTPClient()
http:request(requestUrl, {
options = {
method = 'PUT',
data = message
},
success = successCallback,
error = errorCallback
})
end
message = '{"id": 441, "iconID": 1003}' -- this scene id = 441 and new icon id = 1003 ROUGE
putMethod(url,
function(resp)
print('Status de la fonction HTTP PUT ROUGE: ' .. resp.status)
end,
function(err)
print('error' .. err)
end
)
end