-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
41 lines (37 loc) · 1.98 KB
/
script.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
function ToggleShelly(type, id, ip) {
fetch('http://' + ip +'/'+ type +'/' + id + '?turn=toggle')
.then()
.catch(err => alert('Toggle failed'));
}
function loadData() {
setInterval(
function() {
$("div[data-ip]").each(function(){
var ip = $(this).data('ip');
var name = $(this).data('name');
var power = $(this).data('consumption');
var shellytype = $(this).data('type');
var relayindex = $(this).data('relayindex');
var id = $(this).attr('id');
let content = "";
fetch('http://' + ip +'/status')
.then(response => response.json())
.then(function(data) {
content += "<div>" + name + "</div>";
if(data.relays[relayindex].ison == true)
content += '<div style="width: 100%; text-align: center;" onclick="ToggleShelly(\'' + shellytype + '\', '+ relayindex + ' ,\'' + ip + '\');"><i style="color: #ffa000;" class="relay relay-off mdi mdi-lightbulb-outline"></i></div>';
else
content += '<div style="width:100%; text-align: center;" onclick="ToggleShelly(\'' + shellytype + '\',' + relayindex + ',\'' + ip + '\');"><i class="relay relay-off mdi mdi-lightbulb-outline"></i></div>';
if(typeof data.meters[relayindex].power !== 'undefined')
content += "<div style=\"text-align: center; border-top: 1px solid #ccc; padding-top: 4px; \">";
if (power == true)
content += data.meters[relayindex].power + " Watt";
else
content += "<span style=\"color: #56676f;\">-</span>"
content += "</div>";
$('#' + id ).html(content);
})
});
}, 1000
)
}