aboutsummaryrefslogtreecommitdiff
path: root/.local/share/bin/scene
diff options
context:
space:
mode:
Diffstat (limited to '.local/share/bin/scene')
-rwxr-xr-x.local/share/bin/scene24
1 files changed, 24 insertions, 0 deletions
diff --git a/.local/share/bin/scene b/.local/share/bin/scene
new file mode 100755
index 0000000..f8ea953
--- /dev/null
+++ b/.local/share/bin/scene
@@ -0,0 +1,24 @@
+#!/bin/sh
+
+CACHE_FILE="$XDG_CACHE_HOME/hass-scenes"
+update_cache() {
+ rm -f "$CACHE_FILE"
+ curl -s -X GET \
+ -H "Authorization: Bearer $HASS_TOKEN" \
+ -H "Content-Type: application/json" \
+ "$HASS_SERVER/api/states" |\
+ jq --raw-output ".[] | \"\\(.attributes.friendly_name) (\\(.entity_id))\"" |\
+ grep '(scene\..*)$' > "$CACHE_FILE"
+}
+
+[ ! -e "$CACHE_FILE" -o "$1" = "update" ] && update_cache
+
+entity="$(cat "$CACHE_FILE" |\
+ rofi -dmenu |\
+ sed 's/^.*(\(.*\))$/\1/' |\
+ jq --raw-input)"
+jq -n --argjson entity "$entity" '{"entity_id": $entity}' |\
+ curl -s -X POST -d @- \
+ -H "Authorization: Bearer $HASS_TOKEN" \
+ -H "Content-Type: application/json" \
+ "$HASS_SERVER/api/services/scene/turn_on" > /dev/null