This repository has been archived by the owner on Nov 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
get_awattar_data_1.1.js
82 lines (65 loc) · 2.65 KB
/
get_awattar_data_1.1.js
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
/*
MIT License - see LICENSE.md
Copyright (c) [2020] [Matthias Boettger <[email protected]>]
*/
var addprice = 18.52;
const url = "https://api.awattar.de/v1/marketdata";
function requestData() {
const options = {
url: url,
method: 'GET'
};
request(options, (error, response, body) => {
if(error) return console.log(error);
if(response.statusCode == 200) {
let array = JSON.parse(body).data;
for(let i = 0; i < array.length; i++) {
let stateBaseName = "electricity.prices." + i + ".";
createState(stateBaseName + "startTime", "", {
read: true,
write: true,
name: "Gultigkeitsbeginn (Uhrzeit)",
type: "string",
def: false
});
createState(stateBaseName + "startDate", "", {
read: true,
write: true,
name: "Gultigkeitsbeginn (Datum)",
type: "string",
def: false
});
createState(stateBaseName + "endTime", "", {
read: true,
write: true,
name: "Gultigkeitsende (Uhrzeit)",
type: "string",
def: false
});
createState(stateBaseName + "price", 0, {
read: true,
write: true,
name: "Preis",
type: "number",
def: 0
});
let start = new Date(array[i].start_timestamp);
var options = { hour12: false, hour: '2-digit', minute:'2-digit'};
let startTime = start.toLocaleTimeString('de-DE', options);
let startDate = start.toLocaleDateString('de-DE');
let end = new Date(array[i].end_timestamp);
let endTime = end.toLocaleTimeString('de-DE', options);
let mwhprice = array[i].marketprice;
let price = ( Number(mwhprice) * 1.19 / 10 ) + addprice;
setState(stateBaseName + "startTime", startTime);
setState(stateBaseName + "startDate", startDate);
setState(stateBaseName + "endTime", endTime);
setState(stateBaseName + "price", price);
};
};
});
}
requestData();
schedule("0,30 * * * *", function () {
requestData();
});