Skip to content

Instantly share code, notes, and snippets.

@noahlt
Last active September 8, 2020 18:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahlt/366cc7881049489994f6ced1a3758379 to your computer and use it in GitHub Desktop.
Save noahlt/366cc7881049489994f6ced1a3758379 to your computer and use it in GitHub Desktop.
curl -s https://www.purpleair.com/json?show=$SENSOR_ID | jq '.results[] | .PM2_5Value' | sed -e 's/^"//' -e 's/"$//' | awk '{ total += $1; count++ } END { print total/count }'
#!/usr/bin/env bash
SENSOR_ID=1 # replace this with your sensor
PM25=$(curl -s https://www.purpleair.com/json?show=$SENSOR_ID |
jq '.results[] | .PM2_5Value' |
sed -e 's/^"//' -e 's/"$//' |
awk '{ total += $1; count++ } END { print int(total/count*100) }')
if [ "$PM25" -le 1200 ]; then
LABEL="GOOD"
else
LABEL="BAD"
fi
echo "$LABEL ($(echo "scale=2; $PM25/100" | bc -l))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment