Skip to main content

Read data from sds011 sensor, gather purpleair and notion data and POST to an API

Project description

Installation

  • Install the monitor_air_quality python package
    • This is best done in a virtualenv or with pip install --user monitor_air_quality
  • Create a ~/.config/monitor_air_quality_config.yaml file with config settings
  • Run monitor_air_quality --help to see the options

Usage

usage: monitor_air_quality.py [-h] [--fetch-local-aqi LOCATION]
                              [--fetch-notion-temperature LOCATION]
                              [--notion-sensor SENSOR_NAME]
                              [--fetch-purpleair-data LOCATION]
                              [--command COMMAND]
                              [--alert LOCATION,METRIC,THRESHOLD]
                              [--alert-on-temperature-inversion LOCATION,LOCATION]
                              [--output {print,debug,info,post}]

Gather and post or print air quality and temperature data

optional arguments:
  -h, --help            show this help message and exit
  --fetch-local-aqi LOCATION
                        the local location to use when fetching local data
  --fetch-notion-temperature LOCATION
                        the location to use when fetching the notion API for
                        temperature data
  --notion-sensor SENSOR_NAME
                        the notion sensor name to fetch from
  --fetch-purpleair-data LOCATION
                        the location to use when fetching purpleair data
  --command COMMAND     command to run to fetch remote data
  --alert LOCATION,METRIC,THRESHOLD
                        comma delimited string of location,metric,threshold
  --alert-on-temperature-inversion LOCATION,LOCATION
                        comma delimited string of indoor,outdoor location
                        names
  --output {print,debug,info,post}
                        whether to print or post the results or give debug or
                        info output (default: print)

Examples:
    --command "ssh pi@203.0.113.20 'monitor_air_quality --fetch-local-aqi upstairs'"
    --fetch-local-aqi basement --alert basement,pm25,12
    --notion-sensor "Upstairs hall Sensor" --fetch-notion-temperature upstairs
    --fetch-purpleair-data outdoor
    --alert-on-temperature-inversion upstairs,outdoor --notion-sensor "Upstairs hall Sensor" --fetch-notion-temperature upstairs --fetch-purpleair-data outdoor
    --fetch-local-aqi basement --notion-sensor "Upstairs hall Sensor" --fetch-notion-temperature upstairs --fetch-purpleair-data outdoor --command "ssh -i /home/gene/Documents/monitor_air_quality/id_rsa pi@192.168.0.31 true" --alert upstairs,pm25,12 --alert-on-temperature-inversion upstairs,outdoor

Example outputs

Output print

{
    "dt": "2021-09-12T13:25:26.460173",
    "upstairs": {
        "pm25": "4.2",
        "pm10": "7.7",
        "aqipm25": "18",
        "aqipm10": "6",
        "temp_f": "69.99"
    },
    "basement": {
        "pm25": "4.0",
        "pm10": "9.7",
        "aqipm25": "17",
        "aqipm10": "8"
    },
    "outdoor": {
        "pm25": "11.96",
        "pm10": "13.56",
        "LastSeen": 1631478276,
        "humidity": "39",
        "temp_f": "72.57",
        "pressure": "1014.62",
        "aqipm25": "50",
        "aqipm10": "12"
    }
}

Output post or info

INFO:root:Command executed : ssh pi@203.0.113.20 monitor_air_quality : {'dt': '2021-09-12T13:28:27.219094', 'upstairs': {'pm25': '3.7', 'pm10': '6.4', 'aqipm25': '15', 'aqipm10': '6'}}
INFO:root:Local air quality data fetched {'pm25': '4.0', 'pm10': '8.6', 'aqipm25': '17', 'aqipm10': '7'}
INFO:root:Notion temperature data fetched : 69.99
INFO:root:Purpleair data fetched {'pm25': '11.57', 'pm10': '12.63', 'LastSeen': 1631478516, 'humidity': '39', 'temp_f': '73.57', 'pressure': '1014.6', 'aqipm25': '48', 'aqipm10': '11'}
INFO:root:Metric upstairs pm25 3.7 continues to not exceed 12. No transition occurred
INFO:root:It continues to be warmer outside 73.57 than inside 69.99. No transition occurred

Notes

I ended up using the py-sds011 library instead of the sds011 library or just interacting with the serial device directly as it seemed to work the best for me.

I also chose to use "query mode" instead of "active mode" for the sds011 sensor, though I'm not entirely sure I understand the difference.

Sampling for 30 seconds every 5 minutes would use up 800 of the 1000 hour life of the sensor in 1 year. I will likely drop this down to 30 seconds every 10 minutes or more.

I read somewhere that the manufacturer recommends a 30 second sample but don't know where that's written.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monitor_air_quality-2.0.0.tar.gz (21.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monitor_air_quality-2.0.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

Details for the file monitor_air_quality-2.0.0.tar.gz.

File metadata

  • Download URL: monitor_air_quality-2.0.0.tar.gz
  • Upload date:
  • Size: 21.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

File hashes

Hashes for monitor_air_quality-2.0.0.tar.gz
Algorithm Hash digest
SHA256 8f90e291989e503acba2f13bf5323906134a275d84bc87ec62c3220fe7fe93d8
MD5 9d683be9601b7107ba75a22b77f6c8f4
BLAKE2b-256 844d1b27b0941ef19d008cbb84f084055b72b4aa75ca1c601699d28e0722bedd

See more details on using hashes here.

File details

Details for the file monitor_air_quality-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: monitor_air_quality-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 23.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

File hashes

Hashes for monitor_air_quality-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5ba1328ebec19b2931c3bc76183e2be92c96b3277b149832f092b52398da3b7d
MD5 a10c1ef0e66f637254a6d9bc28099540
BLAKE2b-256 8937149e17e74612f64a5a6529e344f0393e40e013815de0b1c5b40a12eebb5b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page