-- Hämta Tibberdata
local tibberToken = "MinToken"
function checkTibber()
net.HTTPClient():request( '
https://api.tibber.com/v1-beta/gql', {
options = {
method="POST",
headers={ ['Authorization'] = 'Bearer' ..tibberToken, ['Content-Type'] = 'application/json' },
data= '{ "query": "{viewer {homes {currentSubscription {priceInfo {current {total energy tax startsAt level}today{total energy tax startsAt level}tomorrow{total energy tax startsAt level}}}}}}"}'},
success = function (response)
local decodedResponse = json.decode(response.data)
local TibberElpris = tonumber(decodedResponse.data.viewer.homes[2].currentSubscription.priceInfo.current.total)
fibaro:debug ("Elpris: " .. TibberElpris)
rule("elpris = ".. TibberElpris)
fibaro:setGlobal ('Level', (decodedResponse.data.viewer.homes[2].currentSubscription.priceInfo.current.level))
fibaro:getGlobalValue('Level')
fibaro:debug ("response.data:"..response.data) -- Today Tomorrow
end,
error = function (err) fibaro:debug ("Error: " .. err) end })
end
Util.defTriggerVar('elpris',0)
rule("@@01:00:00 => checkTibber()") -- check Tibber every hour...?
rule("$Level=='VERY_CHEAP' | $Level=='CHEAP' => Bergvarmepump.tariffB:off;log('TariffB off')")
rule("$Level=='NORMAL' | $Level=='EXPENSIVE' | $Level=='VERY_EXPENSIVE' => Bergvarmepump.tariffB:on;log('Tariff B on ')")
-- Hämta Tibberdata