|
@@ -0,0 +1,146 @@
|
|
1
|
+<!doctype html>
|
|
2
|
+<html lang="en">
|
|
3
|
+ <head>
|
|
4
|
+ <meta charset="utf-8">
|
|
5
|
+ <meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+ <meta name="color-scheme" content="dark light">
|
|
7
|
+ <title>Lights Control</title>
|
|
8
|
+ <!--<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">-->
|
|
9
|
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/css/bootstrap-dark.min.css" rel="stylesheet">
|
|
10
|
+ </head>
|
|
11
|
+
|
|
12
|
+ <body>
|
|
13
|
+ <div class="container text-center">
|
|
14
|
+ <div class="row">
|
|
15
|
+ <div class="col">
|
|
16
|
+ <h1>Lights Control</h1>
|
|
17
|
+ </div>
|
|
18
|
+ </div>
|
|
19
|
+
|
|
20
|
+ <nav>
|
|
21
|
+ <div class="nav nav-tabs" id="nav-tab" role="tablist">
|
|
22
|
+ <button class="nav-link active" id="nav-bathroom-tab" data-bs-toggle="tab" data-bs-target="#nav-bathroom" type="button" role="tab" aria-controls="nav-bathroom" aria-selected="true">
|
|
23
|
+ Bathroom
|
|
24
|
+ </button>
|
|
25
|
+ <button class="nav-link" id="nav-livingroom-tab" data-bs-toggle="tab" data-bs-target="#nav-livingroom" type="button" role="tab" aria-controls="nav-livingroom" aria-selected="false">
|
|
26
|
+ Livingroom
|
|
27
|
+ </button>
|
|
28
|
+ </div>
|
|
29
|
+ </nav>
|
|
30
|
+
|
|
31
|
+ <div class="row">
|
|
32
|
+ <div class="col">
|
|
33
|
+ <hr>
|
|
34
|
+ </div>
|
|
35
|
+ </div>
|
|
36
|
+
|
|
37
|
+ <div class="tab-content" id="nav-tabContent">
|
|
38
|
+ <div class="tab-pane fade show active" id="nav-bathroom" role="tabpanel" aria-labelledby="nav-bathroom-tab" tabindex="0">
|
|
39
|
+ <div class="row">
|
|
40
|
+ <div class="col">
|
|
41
|
+ Lights
|
|
42
|
+ </div>
|
|
43
|
+ <div class="col">
|
|
44
|
+ <div class="btn-group" role="group">
|
|
45
|
+ <input type="radio" class="btn-check" name="btnradio" id="bathroomlightauto" autocomplete="off">
|
|
46
|
+ <label class="btn btn-outline-primary" for="bathroomlightauto">
|
|
47
|
+ Auto
|
|
48
|
+ </label>
|
|
49
|
+ <input type="radio" class="btn-check" name="btnradio" id="bathroomlightbig" autocomplete="off">
|
|
50
|
+ <label class="btn btn-outline-success" for="bathroomlightbig">
|
|
51
|
+ Big
|
|
52
|
+ </label>
|
|
53
|
+ <input type="radio" class="btn-check" name="btnradio" id="bathroomlightsmall" autocomplete="off">
|
|
54
|
+ <label class="btn btn-outline-info" for="bathroomlightsmall">
|
|
55
|
+ Small
|
|
56
|
+ </label>
|
|
57
|
+ <input type="radio" class="btn-check" name="btnradio" id="bathroomlightoff" autocomplete="off">
|
|
58
|
+ <label class="btn btn-outline-dark" for="bathroomlightoff">
|
|
59
|
+ Off
|
|
60
|
+ </label>
|
|
61
|
+ </div>
|
|
62
|
+ </div>
|
|
63
|
+ </div>
|
|
64
|
+ </div>
|
|
65
|
+
|
|
66
|
+ <div class="tab-pane fade" id="nav-livingroom" role="tabpanel" aria-labelledby="nav-livingroom-tab" tabindex="0">
|
|
67
|
+ <div class="row">
|
|
68
|
+ <div class="col">
|
|
69
|
+ <p>No controls available yet.</p>
|
|
70
|
+ </div>
|
|
71
|
+ </div>
|
|
72
|
+ </div>
|
|
73
|
+ </div>
|
|
74
|
+
|
|
75
|
+ <div class="row">
|
|
76
|
+ <div class="col">
|
|
77
|
+ <hr>
|
|
78
|
+ </div>
|
|
79
|
+ </div>
|
|
80
|
+
|
|
81
|
+ <div class="row">
|
|
82
|
+ <div class="col">
|
|
83
|
+ <p>Please wait after opening the page until the buttons change to reflect the current state of the lights. If that doesn't happen after a couple of seconds, there is probably a connection problem.</p>
|
|
84
|
+ </div>
|
|
85
|
+ </div>
|
|
86
|
+ <div class="row">
|
|
87
|
+ <div class="col">
|
|
88
|
+ <p><b>Please note:</b> this only works when the MQTT broker and the NodeRED logic are working properly. Also not all web browsers support web socket connections to the MQTT broker. Firefox gives problems, so try a Chromium based browser instead.</p>
|
|
89
|
+ </div>
|
|
90
|
+ </div>
|
|
91
|
+ </div>
|
|
92
|
+
|
|
93
|
+ <!--<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>-->
|
|
94
|
+ <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
95
|
+ <script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
|
|
96
|
+ <script src="lights.js"></script>
|
|
97
|
+
|
|
98
|
+ <script>
|
|
99
|
+ const btns = document.querySelectorAll("#bathroomlightauto, #bathroomlightbig, #bathroomlightsmall, #bathroomlightoff")
|
|
100
|
+
|
|
101
|
+ // handle changes to bathroom lights
|
|
102
|
+ subscribeTopic("bathroom/force_light", function (msg) {
|
|
103
|
+ // clear all buttons
|
|
104
|
+ for (const btn of btns) {
|
|
105
|
+ btn.checked = false
|
|
106
|
+ }
|
|
107
|
+
|
|
108
|
+ // activate proper button
|
|
109
|
+ if (msg == "none") {
|
|
110
|
+ const btn = document.querySelector("#bathroomlightauto")
|
|
111
|
+ btn.checked = true
|
|
112
|
+ } else if (msg == "big") {
|
|
113
|
+ const btn = document.querySelector("#bathroomlightbig")
|
|
114
|
+ btn.checked = true
|
|
115
|
+ } else if (msg == "small") {
|
|
116
|
+ const btn = document.querySelector("#bathroomlightsmall")
|
|
117
|
+ btn.checked = true
|
|
118
|
+ } else if (msg == "off") {
|
|
119
|
+ const btn = document.querySelector("#bathroomlightoff")
|
|
120
|
+ btn.checked = true
|
|
121
|
+ } else {
|
|
122
|
+ console.log("unknown msg " + msg)
|
|
123
|
+ }
|
|
124
|
+ })
|
|
125
|
+
|
|
126
|
+ // set new bathroom light state
|
|
127
|
+ for (const btn of btns) {
|
|
128
|
+ btn.addEventListener('change', function (e) {
|
|
129
|
+ if (this.checked) {
|
|
130
|
+ if (this == document.querySelector("#bathroomlightauto")) {
|
|
131
|
+ setTopic("bathroom/force_light", "none")
|
|
132
|
+ } else if (this == document.querySelector("#bathroomlightbig")) {
|
|
133
|
+ setTopic("bathroom/force_light", "big")
|
|
134
|
+ } else if (this == document.querySelector("#bathroomlightsmall")) {
|
|
135
|
+ setTopic("bathroom/force_light", "small")
|
|
136
|
+ } else if (this == document.querySelector("#bathroomlightoff")) {
|
|
137
|
+ setTopic("bathroom/force_light", "off")
|
|
138
|
+ } else {
|
|
139
|
+ console.log("unknown btn value " + this.value)
|
|
140
|
+ }
|
|
141
|
+ }
|
|
142
|
+ })
|
|
143
|
+ }
|
|
144
|
+ </script>
|
|
145
|
+ </body>
|
|
146
|
+</html>
|