|
@@ -0,0 +1,37 @@
|
|
1
|
+title: MQTT Webinterface
|
|
2
|
+description: Using Bootstrap and JavaScript for universal controls
|
|
3
|
+parent: smarthome
|
|
4
|
+position: 400
|
|
5
|
+git: https://git.xythobuz.de/thomas/lights-web
|
|
6
|
+date: 2022-08-14
|
|
7
|
+comments: true
|
|
8
|
+---
|
|
9
|
+
|
|
10
|
+<!--% backToParent() %-->
|
|
11
|
+
|
|
12
|
+Both my [ESP-Env sensors and actors](espenv.html) as well as the [Node-RED automation](nodered.html) are interfacing to the network using MQTT.
|
|
13
|
+
|
|
14
|
+This allows easy control using for example the [mosquitto_pub](https://mosquitto.org/man/mosquitto_pub-1.html) MQTT command line client.
|
|
15
|
+With these four commands I'm overriding my Node-RED controlled bathroom light automation.
|
|
16
|
+
|
|
17
|
+<pre class="sh_sh">
|
|
18
|
+mosquitto_pub -h $HOSTNAME -u $USERNAME -P $PASSWORD -t bathroom/force_light -r -m none
|
|
19
|
+mosquitto_pub -h $HOSTNAME -u $USERNAME -P $PASSWORD -t bathroom/force_light -r -m big
|
|
20
|
+mosquitto_pub -h $HOSTNAME -u $USERNAME -P $PASSWORD -t bathroom/force_light -r -m small
|
|
21
|
+mosquitto_pub -h $HOSTNAME -u $USERNAME -P $PASSWORD -t bathroom/force_light -r -m off
|
|
22
|
+</pre>
|
|
23
|
+
|
|
24
|
+At the same time the environment sensors also publish their measurements to the corresponding MQTT topics.
|
|
25
|
+
|
|
26
|
+To have a central place where these settings can be viewed and changed, not only for me but also for guests, I decided to write a small interactive web interface.
|
|
27
|
+It interfaces to the MQTT broker using WebSockets.
|
|
28
|
+Unfortunately this only seems to work with Chromium, not Firefox.
|
|
29
|
+
|
|
30
|
+<!--%
|
|
31
|
+lightgallery([
|
|
32
|
+ [ "img/mqtt_lights_web.png", "Screenshot of Lights Control" ],
|
|
33
|
+])
|
|
34
|
+%-->
|
|
35
|
+
|
|
36
|
+You can [find the source code on my Gitea](https://git.xythobuz.de/thomas/lights-web).
|
|
37
|
+I also added the installation and setup instructions to my [ansible scripts](sovereign.html).
|