Ik heb wat data uit de API's gehaald, maar eerlijk is eerlijk ik ben geen expert, dus gebruik ik HomeyScript icm CHatGPT en so far so good, maar kan wat hulp gebruiken:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
| // Login and get access token
var result = await fetch("https://portaal.eplucon.nl/api/v2/auth/login", {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
body: JSON.stringify({
username: 'VULHIERJEUSERNAMEIN',
password: 'VULJEEPLUCONPASSWORDIN'
}),
});
if (!result.ok) throw new Error(result.statusText);
const body = await result.json();
console.log(body)
var access_token = body.access_token;
await tag("eplucon_access_token", access_token);
// Fetch account info
var accountInfo = await fetch("https://portaal.eplucon.nl/api/v2/account/info", {
method: 'get',
headers: {
'Authorization': `Bearer ${access_token}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
if (!accountInfo.ok) throw new Error(accountInfo.statusText);
const accountInfoBody = await accountInfo.json();
console.log(accountInfoBody);
// Fetch list of accounts modules
var modules = await fetch("https://portaal.eplucon.nl/api/v2/econtrol/modules", {
method: 'get',
headers: {
'Authorization': `Bearer ${access_token}`,
'Content-Type': 'application/json',
'Accept': 'application/json'
}
});
if (!modules.ok) throw new Error(modules.statusText);
const modulesBody = await modules.json();
console.log(modulesBody);
// Fetch list of zones
const url = 'https://portaal.eplucon.nl/api/v2/econtrol/modules/3775560267/zones';
const options = {
method: 'GET',
headers: {
'Authorization': `Bearer ${access_token}`,
'Accept': 'application/json'
}
};
try {
const response = await fetch(url, options);
const data = await response.json();
console.log(data);
} catch (error) {
console.error(error);
}
// Fetch statistics
const urlStats = 'https://portaal.eplucon.nl/api/v2/econtrol/modules/1000704/statistics?range=day&month=1&year=2024';
const optionsStats = {
method: 'GET',
headers: {
'Authorization': `Bearer ${access_token}`,
'Accept': 'application/json'
}
};
try {
const responseStats = await fetch(urlStats, optionsStats);
const dataStats = await responseStats.json();
console.log(dataStats);
} catch (error) {
console.error(error);
} |
Dat levert (naast privé output) voor de statistieken deze output op in Homeyscript:
{
auth: true,
style: 'installation',
data: {
data: [
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object], [Object], [Object],
[Object], [Object], [Object], [Object],
... 1024 more items
]
},
Daar kan ik geen virtual device mee vullen, dus ik doe iets fout... maar wat?
[
Voor 0% gewijzigd door
wdool op 22-01-2024 13:32
. Reden: scherper geformuleerd ]