Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
agilje 0
This is a Quickapp script for HC3. I am trying to get this to work in a VD on HC2. Is it possible, or do I have to do it together with a scene to make it work?
Can anyone help?
function QuickApp:onInit()
self:updateProperty("unit", "kr/kWh")
self.refresh = 60 -- in seconds
local function loop()
self:webrequest();
setTimeout(loop,self.refresh * 1000)
end
if self.username ~= "changeme" then loop() end
end
function QuickApp:webrequest()
local tid = os.date("%R")
local minutt = os.date("%M")
--OPPDATERER STRØMPRIS OG SNITT HVER TIME
if (minutt == "00")
then
self:OppdaterPris();
self:OppdaterSnitt();
end
end
function QuickApp:OppdaterPris()
--Opprette lokale variable
local GammelStrompris = fibaro.get(126,"value")
local NyStrompris
--Definerer http
local http = net.HTTPClient();
--Definerer strengen Payload til å være kommando til tibber
local payload = '{"query": "{viewer {homes {currentSubscription{priceInfo{current{total}}}}}}", "variables": null, "operationName": null}';
--API.POST til Tibber--
http : request('https://api.tibber.com/v1-beta/gql', {
options =
{
method = "POST",
headers =
{
['Authorization'] = '.........', --Min Tibber ID her.
['Content-Type'] = 'application/json'
},
data = payload -- Query.
},
success = function(response)
--fibaro.debug (response.data) --Verifiser at en har fått response.data. Dette er data som en har fått fra Tibber
local data = json.decode(response.data);
--fjernet local under???
NyStrompris = json.encode(data.data.viewer.homes[1].currentSubscription.priceInfo.current.total);
self:updateProperty("value", tonumber(NyStrompris))
--print("OK")
end,
error = function(err) fibaro.debug ("Error:" .. err)
end
});
end
function QuickApp:OppdaterSnitt()
--Definerer http
local http = net.HTTPClient();
--Definerer strengen average til å være kommando til tibber
local average = '{"query": "{viewer {homes {currentSubscription{priceRating{daily{entries{total}}}}}}}", "variables": null, "operationName": null}';
--API.POST Til Tibber
Edited by agiljehttp : request
('https://api.tibber.com/v1-beta/gql',
{
options =
{
method = "POST",
headers =
{
['Authorization'] = '...............', --Min Tibber ID her.
['Content-Type'] = 'application/json'
},
data = average -- Query
},
success = function(response)
--fibaro.debug(response.data) --Verifiser at en har fått response.data. Dette er data som en har fått fra Tibber
local data = json.decode(response.data);
local Nypris = tostring(json.encode(data.data.viewer.homes[1].currentSubscription.priceRating.daily.entries[31].total));
self:updateProperty("log", tostring(Nypris))
end,
}
)
end
Remove personal info
1 answer to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.