Last active
September 8, 2020 18:24
-
-
Save noahlt/366cc7881049489994f6ced1a3758379 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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 }' |
This file contains 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 characters
#!/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