-
-
Save r15ch13/8bbd87f9ad6f70eefea044c45dc7cd53 to your computer and use it in GitHub Desktop.
Revisions
-
r15ch13 created this gist
May 22, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ HA_HOST=http://myhomeassistant:8123 HA_TOKEN=long lived token HA_SWITCH=entity_id This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ #!/bin/bash source $(dirname $0)/.ha HA_BODY="{\"entity_id\": \"${HA_SWITCH}\"}" case "$1" in on) curl -s -X POST -H "Authorization: Bearer ${HA_TOKEN}" \ -H "Content-Type: application/json" \ -d "$HA_BODY" \ "${HA_HOST}/api/services/switch/turn_on" > /dev/null ;; off) curl -s -X POST -H "Authorization: Bearer ${HA_TOKEN}" \ -H "Content-Type: application/json" \ -d "$HA_BODY" \ "${HA_HOST}/api/services/switch/turn_off" > /dev/null ;; status) curl -s -X GET -H "Authorization: Bearer ${HA_TOKEN}" \ -H "Content-Type: application/json" \ "${HA_HOST}/api/states/${HA_SWITCH}" | grep '"state": "on"' exit $? ;; *) echo "Usage $0 on|off|status" exit 1 esac