123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <meta name="color-scheme" content="dark light">
- <title>Lights Control</title>
- <!--<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">-->
- <link href="https://cdn.jsdelivr.net/npm/bootstrap-dark-5@1.1.3/dist/css/bootstrap-dark.min.css" rel="stylesheet">
- </head>
-
- <body>
- <div class="container text-center">
- <div class="row">
- <div class="col">
- <h1>Lights Control</h1>
- </div>
- </div>
-
- <nav>
- <div class="nav nav-tabs" id="nav-tab" role="tablist">
- <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">
- Livingroom
- </button>
- <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">
- Bathroom
- </button>
- <button class="nav-link" id="nav-help-tab" data-bs-toggle="tab" data-bs-target="#nav-help" type="button" role="tab" aria-controls="nav-help" aria-selected="false">
- Help
- </button>
- </div>
- </nav>
-
- <div class="row">
- <div class="col">
- <hr>
- </div>
- </div>
-
- <div class="tab-content" id="nav-tabContent">
- <div class="tab-pane fade show active" id="nav-bathroom" role="tabpanel" aria-labelledby="nav-bathroom-tab" tabindex="0">
- <div class="row">
- <div class="col">
- <h2>Actors</h2>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <p>Lights</p>
- </div>
- <div class="col">
- <div class="btn-group" role="group">
- <input type="radio" class="btn-check" name="bathroomradio" id="bathroomlightauto" autocomplete="off">
- <label class="btn btn-outline-primary" for="bathroomlightauto">
- Auto
- </label>
- <input type="radio" class="btn-check" name="bathroomradio" id="bathroomlightbig" autocomplete="off">
- <label class="btn btn-outline-success" for="bathroomlightbig">
- Big
- </label>
- <input type="radio" class="btn-check" name="bathroomradio" id="bathroomlightsmall" autocomplete="off">
- <label class="btn btn-outline-info" for="bathroomlightsmall">
- Small
- </label>
- <input type="radio" class="btn-check" name="bathroomradio" id="bathroomlightoff" autocomplete="off">
- <label class="btn btn-outline-dark" for="bathroomlightoff">
- Off
- </label>
- </div>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <hr>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <h2>Sensors</h2>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <p>Temperature</p>
- </div>
- <div class="col" id="bathtemp">
- <p>Unknown</p>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <p>Relative Humidity</p>
- </div>
- <div class="col" id="bathhumid">
- <p>Unknown</p>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <p>tVOC</p>
- </div>
- <div class="col" id="bathtvoc">
- <p>Unknown</p>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <p>eCo2</p>
- </div>
- <div class="col" id="batheco2">
- <p>Unknown</p>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <p>Air Pressure</p>
- </div>
- <div class="col" id="bathpress">
- <p>Unknown</p>
- </div>
- </div>
- </div>
-
- <div class="tab-pane fade" id="nav-livingroom" role="tabpanel" aria-labelledby="nav-livingroom-tab" tabindex="0">
- <div class="row">
- <div class="col">
- <p>No controls available yet.</p>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <p>Workspace Lights</p>
- </div>
- <div class="col">
- <div class="btn-group" role="group">
- <input type="radio" class="btn-check" name="workspaceradio" id="workspaceon" autocomplete="off">
- <label class="btn btn-outline-primary" for="workspaceon">
- On
- </label>
- <input type="radio" class="btn-check" name="workspaceradio" id="workspaceoff" autocomplete="off">
- <label class="btn btn-outline-dark" for="workspaceoff">
- Off
- </label>
- </div>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <p>TV Lights</p>
- </div>
- <div class="col">
- <div class="btn-group" role="group">
- <input type="radio" class="btn-check" name="tvradio" id="tvon" autocomplete="off">
- <label class="btn btn-outline-primary" for="tvon">
- On
- </label>
- <input type="radio" class="btn-check" name="tvradio" id="tvoff" autocomplete="off">
- <label class="btn btn-outline-dark" for="tvoff">
- Off
- </label>
- </div>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <p>Kitchen Lights</p>
- </div>
- <div class="col">
- <div class="btn-group" role="group">
- <input type="radio" class="btn-check" name="kitchenradio" id="kitchenon" autocomplete="off">
- <label class="btn btn-outline-primary" for="kitchenon">
- On
- </label>
- <input type="radio" class="btn-check" name="kitchenradio" id="kitchenoff" autocomplete="off">
- <label class="btn btn-outline-dark" for="kitchenoff">
- Off
- </label>
- </div>
- </div>
- </div>
- </div>
-
- <div class="tab-pane fade" id="nav-help" role="tabpanel" aria-labelledby="nav-help-tab" tabindex="0">
- <div class="row">
- <div class="col">
- <p><a href=".">Refresh page</a></p>
- </div>
- </div>
- <div class="row">
- <div class="col">
- <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>
- </div>
- </div>
- <div class="row">
- <div class="col">
- <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>
- </div>
- </div>
- </div>
- </div>
-
- <div class="row">
- <div class="col">
- <hr>
- </div>
- </div>
-
- </div>
-
- <!--<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>-->
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"></script>
- <script src="https://unpkg.com/mqtt/dist/mqtt.min.js"></script>
-
- <script src="credentials.js"></script>
- <script src="lights.js"></script>
-
- <script>
- const btnsBath = document.querySelectorAll("#bathroomlightauto, #bathroomlightbig, #bathroomlightsmall, #bathroomlightoff")
-
- // handle changes to bathroom lights
- subscribeTopic("bathroom/force_light", function (msg) {
- // clear all buttons
- for (const btn of btnsBath) {
- btn.checked = false
- }
-
- // activate proper button
- if (msg == "none") {
- const btn = document.querySelector("#bathroomlightauto")
- btn.checked = true
- } else if (msg == "big") {
- const btn = document.querySelector("#bathroomlightbig")
- btn.checked = true
- } else if (msg == "small") {
- const btn = document.querySelector("#bathroomlightsmall")
- btn.checked = true
- } else if (msg == "off") {
- const btn = document.querySelector("#bathroomlightoff")
- btn.checked = true
- } else {
- console.log("unknown msg " + msg)
- }
- })
-
- // set new bathroom light state
- for (const btn of btnsBath) {
- btn.addEventListener('change', function (e) {
- if (this.checked) {
- if (this == document.querySelector("#bathroomlightauto")) {
- setTopic("bathroom/force_light", "none")
- } else if (this == document.querySelector("#bathroomlightbig")) {
- setTopic("bathroom/force_light", "big")
- } else if (this == document.querySelector("#bathroomlightsmall")) {
- setTopic("bathroom/force_light", "small")
- } else if (this == document.querySelector("#bathroomlightoff")) {
- setTopic("bathroom/force_light", "off")
- } else {
- console.log("unknown btn value " + this.value)
- }
- }
- })
- }
-
- // handle bathroom sensors
- subscribeTopic("bathroom/temperature", function (msg) {
- const txt = document.querySelector("#bathtemp")
- txt.innerHTML = "<p>" + msg + " °C</p>"
- })
- subscribeTopic("bathroom/humidity", function (msg) {
- const txt = document.querySelector("#bathhumid")
- txt.innerHTML = "<p>" + msg + " %</p>"
- })
- subscribeTopic("bathroom/pressure", function (msg) {
- const txt = document.querySelector("#bathpress")
- txt.innerHTML = "<p>" + msg + " Pa</p>"
- })
- subscribeTopic("bathroom/tvoc", function (msg) {
- const txt = document.querySelector("#bathtvoc")
- txt.innerHTML = "<p>" + msg + "</p>"
- })
- subscribeTopic("bathroom/eco2", function (msg) {
- const txt = document.querySelector("#batheco2")
- txt.innerHTML = "<p>" + msg + " ppm</p>"
- })
- </script>
- </body>
- </html>
|