123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <!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 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-livingroom-tab" data-bs-toggle="tab" data-bs-target="#nav-livingroom" type="button" role="tab" aria-controls="nav-livingroom" aria-selected="false">
- Livingroom
- </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">
- Lights
- </div>
- <div class="col">
- <div class="btn-group" role="group">
- <input type="radio" class="btn-check" name="btnradio" id="bathroomlightauto" autocomplete="off">
- <label class="btn btn-outline-primary" for="bathroomlightauto">
- Auto
- </label>
- <input type="radio" class="btn-check" name="btnradio" id="bathroomlightbig" autocomplete="off">
- <label class="btn btn-outline-success" for="bathroomlightbig">
- Big
- </label>
- <input type="radio" class="btn-check" name="btnradio" id="bathroomlightsmall" autocomplete="off">
- <label class="btn btn-outline-info" for="bathroomlightsmall">
- Small
- </label>
- <input type="radio" class="btn-check" name="btnradio" id="bathroomlightoff" autocomplete="off">
- <label class="btn btn-outline-dark" for="bathroomlightoff">
- Off
- </label>
- </div>
- </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>
- </div>
-
- <div class="row">
- <div class="col">
- <hr>
- </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>
-
- <!--<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="lights.js"></script>
-
- <script>
- const btns = document.querySelectorAll("#bathroomlightauto, #bathroomlightbig, #bathroomlightsmall, #bathroomlightoff")
-
- // handle changes to bathroom lights
- subscribeTopic("bathroom/force_light", function (msg) {
- // clear all buttons
- for (const btn of btns) {
- 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 btns) {
- 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)
- }
- }
- })
- }
- </script>
- </body>
- </html>
|