From 8cd1111fa3420e3343f2cf19b0a7b49aa48631fe Mon Sep 17 00:00:00 2001 From: Penelope Gwen Date: Tue, 22 Apr 2025 10:36:52 -0700 Subject: [PATCH] New backup 2025-04-22 10:36:52 --- default/home/.local/bin/hass-cli | 45 ++++++++++++++++++++++++++++++++ default/include | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 default/home/.local/bin/hass-cli diff --git a/default/home/.local/bin/hass-cli b/default/home/.local/bin/hass-cli new file mode 100755 index 0000000..1d82784 --- /dev/null +++ b/default/home/.local/bin/hass-cli @@ -0,0 +1,45 @@ +#!/usr/bin/env bash + +#https://developers.home-assistant.io/docs/api/rest/ + +source "${HOME}/.secrets" + +while getopts "a:e:d:s:" flag; do + case $flag in + a) + action="${OPTARG}" + ;; + e) + entity_id="${OPTARG}" + ;; + d) + domain="${OPTARG}" + ;; + s) + service="${OPTARG}" + ;; + *) + printf '%s' "bad option: ${flag}" + ;; + esac +done + +#echo "action: ${action}" +#echo "entity_id: ${entity_id}" + +case "${action}" in + "states") + curl -s \ + -H "Authorization: Bearer ${HA_TOKEN}" \ + -H "Content-Type: application/json" \ + "${HA_URL}/api/${action}/${entity_id}" | jq '.' + ;; + "services") +# echo '{"entity_id": "'"${entity_id}"'"}' + curl -s \ + -H "Authorization: Bearer ${HA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{"entity_id": "'"${entity_id}"'"}' \ + "${HA_URL}/api/${action}/${domain}/${service}" | jq '.' + ;; +esac diff --git a/default/include b/default/include index 96e9436..d3637c2 100644 --- a/default/include +++ b/default/include @@ -7,4 +7,4 @@ Scripts/create-podman-container.sh Scripts/create-podman-container-arm.sh .local/lib/python3.13/site-packages/ssi.py .local/bin/ssi-server -Scripts/ha +.local/bin/hass-cli