Initial reusable HA kiosk MQTT controls
This commit is contained in:
commit
0b7e6a0107
17 files changed
+3249
No files matched your search
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
set -u
|
||||
|
||||
KIOSK_CONFIG_FILE="${KIOSK_CONFIG_FILE:-$HOME/.config/ha-kiosk/config}"
|
||||
if [[ -r "$KIOSK_CONFIG_FILE" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "$KIOSK_CONFIG_FILE"
|
||||
fi
|
||||
: "${KIOSK_ID:=kiosk}"
|
||||
: "${COMMAND_ROOT:=kiosk/commands}"
|
||||
: "${STATUS_ROOT:=kiosk/status}"
|
||||
AVAILABILITY_TOPIC="${STATUS_ROOT}/${KIOSK_ID}/availability"
|
||||
PING_TOPIC="${COMMAND_ROOT}/${KIOSK_ID}/availability/ping"
|
||||
PUBLISH_INTERVAL_SECONDS="${AVAILABILITY_INTERVAL_SECONDS:-30}"
|
||||
|
||||
publish_available() {
|
||||
/usr/bin/mosquitto_pub -r -t "$AVAILABILITY_TOPIC" -m "ON"
|
||||
}
|
||||
|
||||
# Keep the MQTT connection that owns the Last Will open in the background.
|
||||
/usr/bin/mosquitto_sub \
|
||||
-t "$PING_TOPIC" \
|
||||
--will-topic "$AVAILABILITY_TOPIC" \
|
||||
--will-payload "OFF" \
|
||||
--will-retain &
|
||||
subscriber_pid=$!
|
||||
|
||||
cleanup() {
|
||||
kill "$subscriber_pid" 2>/dev/null || true
|
||||
wait "$subscriber_pid" 2>/dev/null || true
|
||||
}
|
||||
trap cleanup EXIT INT TERM
|
||||
|
||||
# Reassert retained availability after Mosquitto reconnects internally. The
|
||||
# Last Will has already published OFF when a broker connection was lost.
|
||||
while kill -0 "$subscriber_pid" 2>/dev/null; do
|
||||
publish_available || true
|
||||
sleep "$PUBLISH_INTERVAL_SECONDS"
|
||||
done
|
||||
|
||||
wait "$subscriber_pid"
|
||||
@@ -0,0 +1,25 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# Per-kiosk settings. Copy to ~/.config/ha-kiosk/config.
|
||||
# This file is sourced by Bash; quote values containing spaces.
|
||||
KIOSK_ID=my_kiosk
|
||||
KIOSK_ENTITY_PREFIX=my_kiosk
|
||||
KIOSK_NAME="My Kiosk"
|
||||
KIOSK_MANUFACTURER=Generic
|
||||
KIOSK_MODEL="Linux Touchscreen Kiosk"
|
||||
KIOSK_AREA=""
|
||||
COMMAND_ROOT=kiosk/commands
|
||||
STATUS_ROOT=kiosk/status
|
||||
KIOSK_URL="http://homeassistant.local:8123/"
|
||||
KIOSK_DISPLAY=:0
|
||||
KIOSK_XAUTHORITY="$HOME/.Xauthority"
|
||||
CHROME_BIN=/usr/bin/google-chrome-stable
|
||||
CHROME_USER_DATA_DIR="$HOME/.config/ha-kiosk/chrome-profile"
|
||||
TOUCH_DEVICE_NAME="Touchscreen Device Name"
|
||||
TOUCH_DISPLAY_OUTPUT=eDP-1
|
||||
SCREEN_LOCK_BRIGHTNESS=0
|
||||
BROWSER_SERVICE=ha-kiosk-browser.service
|
||||
MOTION_SERVICE=my_kiosk-motion.service
|
||||
MOTION_EVENT_SCRIPT="$HOME/my_kiosk-motion-event.sh"
|
||||
MQTT_REPUBLISH_INTERVAL_SECONDS=30
|
||||
MQTT_HEARTBEAT_TIMEOUT_SECONDS=90
|
||||
AVAILABILITY_INTERVAL_SECONDS=30
|
||||
@@ -0,0 +1,17 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
[Unit]
|
||||
Description=Home Assistant Kiosk MQTT availability
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
StartLimitIntervalSec=0
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
EnvironmentFile=%h/.config/ha-kiosk/systemd.env
|
||||
ExecStart=%h/.local/lib/ha-kiosk-mqtt-control/availability-watch.sh
|
||||
ExecStopPost=/usr/bin/mosquitto_pub -r -t ${STATUS_ROOT}/${KIOSK_ID}/availability -m OFF
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
@@ -0,0 +1,15 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
[Unit]
|
||||
Description=Home Assistant touchscreen kiosk browser
|
||||
After=graphical-session.target network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
EnvironmentFile=-%h/.config/ha-kiosk/systemd.env
|
||||
ExecStart=%h/.local/lib/ha-kiosk-mqtt-control/ha-kiosk-launcher.sh
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
Executable
+36
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env bash
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
set -euo pipefail
|
||||
|
||||
KIOSK_CONFIG_FILE="${KIOSK_CONFIG_FILE:-$HOME/.config/ha-kiosk/config}"
|
||||
if [[ -r "$KIOSK_CONFIG_FILE" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "$KIOSK_CONFIG_FILE"
|
||||
fi
|
||||
|
||||
: "${KIOSK_URL:?Set KIOSK_URL in ~/.config/ha-kiosk/config}"
|
||||
: "${TOUCH_DEVICE_NAME:=Touchscreen Device Name}"
|
||||
: "${TOUCH_DISPLAY_OUTPUT:=eDP-1}"
|
||||
: "${KIOSK_DISPLAY:=:0}"
|
||||
: "${KIOSK_XAUTHORITY:=$HOME/.Xauthority}"
|
||||
: "${CHROME_BIN:=/usr/bin/google-chrome-stable}"
|
||||
: "${CHROME_USER_DATA_DIR:=$HOME/.config/ha-kiosk/chrome-profile}"
|
||||
export DISPLAY="$KIOSK_DISPLAY"
|
||||
export XAUTHORITY="$KIOSK_XAUTHORITY"
|
||||
|
||||
# Allow the desktop and touchscreen to initialise.
|
||||
sleep 2
|
||||
|
||||
# Map the touchscreen to the rotated built-in display.
|
||||
xinput map-to-output \
|
||||
"$TOUCH_DEVICE_NAME" \
|
||||
"$TOUCH_DISPLAY_OUTPUT"
|
||||
|
||||
# Start Home Assistant in Chrome kiosk mode.
|
||||
"$CHROME_BIN" \
|
||||
--user-data-dir="$CHROME_USER_DATA_DIR" \
|
||||
--kiosk \
|
||||
--noerrdialogs \
|
||||
--disable-session-crashed-bubble \
|
||||
--no-first-run \
|
||||
"$KIOSK_URL"
|
||||
@@ -0,0 +1,15 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
[Unit]
|
||||
Description=Home Assistant Kiosk MQTT Screen Control
|
||||
After=network-online.target graphical-session.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
EnvironmentFile=-%h/.config/ha-kiosk/systemd.env
|
||||
ExecStart=%h/.local/lib/ha-kiosk-mqtt-control/screen-control.sh
|
||||
Restart=always
|
||||
RestartSec=5
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
||||
Executable
+1256
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,4 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# Values used by systemd ExecStopPost. Keep these simple (no spaces).
|
||||
KIOSK_ID=my_kiosk
|
||||
STATUS_ROOT=kiosk/status
|
||||
Reference in new issue
Block a user