Adds very basic hass script
This commit is contained in:
parent
8c0e1ef05a
commit
76e9e832ce
1 changed files with 50 additions and 0 deletions
50
bin/.bin/hass
Executable file
50
bin/.bin/hass
Executable file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
URL="https://hass.hodgson.one"
|
||||||
|
TOKEN="$(pass websites/homeassistant-token)"
|
||||||
|
|
||||||
|
get(){
|
||||||
|
curl --silent --header "Authorization: Bearer $TOKEN" "$URL$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
post(){
|
||||||
|
curl --silent --header "content-type: application/json" --header "Authorization: Bearer $TOKEN" --data-binary @- "$URL$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
listEntities(){
|
||||||
|
get '/api/states' |
|
||||||
|
jq -r '.[] | [.entity_id, .attributes.friendly_name // .entity_id, .state] | @tsv'
|
||||||
|
}
|
||||||
|
|
||||||
|
listServices(){
|
||||||
|
get '/api/services'
|
||||||
|
}
|
||||||
|
|
||||||
|
selectEntity(){
|
||||||
|
listEntities | fzf | cut -d $'\t' -f 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
toggleEntity(){
|
||||||
|
local entity;
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
entity="$1"
|
||||||
|
else
|
||||||
|
entity="$(cat -)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
local domain="${entity%%.*}"
|
||||||
|
|
||||||
|
echo "{\"entity_id\":\"$entity\"}" | post /api/services/$domain/toggle
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
case "$1" in
|
||||||
|
"--listEntities") listEntities ;;
|
||||||
|
"--listServices") listServices ;;
|
||||||
|
*) toggleEntity "$1"
|
||||||
|
esac
|
||||||
|
else
|
||||||
|
selectEntity | toggleEntity
|
||||||
|
fi
|
||||||
Loading…
Add table
Add a link
Reference in a new issue