Scen i HC2 som skickar lite info till MagicMirror (syslog i övre högra hörnet)
Code: Select all
--[[
%% properties
%% events
%% globals
yeasterdayKW
test
--]]
-- USER SETTINGS --
MMip = '192.168.0.137'
MMport = '8080'
local trigger = fibaro:getSourceTrigger();
local daysoftheweek={"Söndag","Måndag","Tisdag","Onsdag","Torsdag","Fredag","Lördag"}
local yesterday = urlencode(daysoftheweek[os.date("*t").wday-1])
function urlencode(str)
if (str) then
str = string.gsub(str, "\n", "\r\n")
str = string.gsub(str, "([^%w ])",
function (c) return string.format ("%%%02X", string.byte(c)) end)
str = string.gsub (str, " ", "+")
end
return str
end
function MM(types,data)
local function getMethod(requestUrl, successCallback, errorCallback)
local http = net.HTTPClient()
http:request(requestUrl, {
options = {
method = 'GET',
headers = {
},
},
success = successCallback,
error = errorCallback
})
end
local url = 'http://'..MMip..':'..MMport..'/syslog?type='..types..'&message='..data
getMethod(url, function(resp)
print(resp.data)
end,
function(err)
print('error' .. err)
end
)
end
if (trigger['type'] == 'global') then
if trigger['varName'] == 'yeasterdayKW' then
MM('INFO',yesterday..'+'..fibaro:getGlobal(trigger['varName'])..'+'..'kWh')
elseif trigger['varName'] == 'test' then
MM('ERROR',fibaro:getGlobal(trigger['varName'])..'+'..'variabel')
end
elseif (trigger['type'] == 'other') then
print('Scene started by other.')
end