Skip to content

Instantly share code, notes, and snippets.

@e-minguez
Created June 25, 2019 13:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e-minguez/40808f7788d726fb4010545e23a5e6fb to your computer and use it in GitHub Desktop.
Save e-minguez/40808f7788d726fb4010545e23a5e6fb to your computer and use it in GitHub Desktop.
HASS="http://1.2.3.4"
TOKEN="middlefinger"
PARAMETERS="-s -X GET -H 'Content-Type: application/json'"
CURL="/usr/bin/curl"
#CURL="curl -s -X GET -H 'Content-Type: application/json' -H \"Authorization: Bearer ${TOKEN}\" ${HASS}/api/states"
${CURL} ${PARAMETERS} -H "Authorization: Bearer ${TOKEN}" --connect-timeout 1 ${HASS}/api/ | grep -q "running"
if [ $? -eq 0 ]
then
TI=$(${CURL} ${PARAMETERS} -H "Authorization: Bearer ${TOKEN}" ${HASS}/api/states/sensor.temperature | jq -r '.state')
TO=$(${CURL} ${PARAMETERS} -H "Authorization: Bearer ${TOKEN}" ${HASS}/api/states/sensor.temperature_outside | jq -r '.state')
HO=$(${CURL} ${PARAMETERS} -H "Authorization: Bearer ${TOKEN}" ${HASS}/api/states/sensor.humidity_outside | jq -r '.state')
echo "${TI}º |"
echo "---"
echo "${TO}º outside"
echo "${HO}% humidity outside"
else
echo "X |"
echo "---"
echo "Unreachable"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment