Coder Social home page Coder Social logo

aqiduck's Introduction

AQIDuck

Logo

NOTE:

This is very data-intensive because it polls the API too frequently, and doesn't batch requests. If you want to use this I would recommend updating it for the new API calls. I am no longer using it myself. Feel free to branch and enjoy!

Purpose:

  • Pull data from PurpleAir
  • Report to Slack about air quality and temperature based on the channel topic
  • Monitor AQI to let you know when it's safe to go outside or no longer safe to go outside based on thresholds you set
  • Or Monitor AQI dynamically to let you know when AQI is trending up or down

Future additions:

  • v2 will allow users to install the app on their slack instance from the app directory

Requirements:

This version requires some minor devops knowledge and understanding of how to get a slackbot up and running

  • You must run the code off of some kind of server that has node on it
  • You must be able to create a slackbot and set up slackbot event subscriptions

To install:

  • Pull the code down onto your server
  • Bundle running yarn install and run yarn build-ts to build the typescript files
  • Get a PurpleAir API Key
  • create a slackbot with the permissions app_mentions:read, channels:read, chat:write, channels:history, groups:read
  • Set up slack event subscriptions:
    • expose a port and calling: ./node_modules/.bin/slack-verify --secret [Signing secret] --port [you pick the port, default 3000]
    • Put the URL of your app in the Event subscriptions part of the slack setup
    • You can find the signing secret in the basic information part of your slack setup
    • Subscribe to the events app_mention, channel_left, member_joined_channel, message.channels
    • cancel the slack-verify server so you can use that same port for the bot
  • Make sure you have all the environment variables set up listed in the example.env
  • Start the server using node . or running the dist/index.js file

To set up:

  • invite the slackbot to various channels
  • set the channel topic to include a JSON string about which PurpleAir sensors should be monitored, for example:
Whatever channel topic you want to write

***{"sensors": [{"name": "Sesame Street", "type": "PurpleAir", "id": 12345}]}***

Monitoring:

If you want your sensor to let you know if the AQI crosses specific boundaries, add AQIThresholds to the topic JSON like so: {"sensors": [{"name": "Whatever", "type": "PurpleAir", "id": 12345, "AQIThresholds":[50,80]}]} Note this currently doesn't validate that the first number is less than the second, and only looks at the first two items.

If you want your sensor to let you know whenever the AQI goes up or down by 5, set AQIMonitoring to dynamic: {"sensors": [{"name": "Whatever", "type": "PurpleAir", "id": 12345, "AQIMonitoring":"dynamic"}]}

If you want your sensor to let you know whenever the AQI crosses to a new category (e.g Good, Unhealthy), set AQIMonitoring to category: {"sensors": [{"name": "Whatever", "type": "PurpleAir", "id": 12345, "AQIMonitoring":"category"}]}

The bot will reload its configuration whenever the channel topic changes.

To talk to the bot:

  • @AQIDuck report gives you the report
  • @AQIDuck stop monitoring stops the monitoring
  • @AQIDuck resume monitoring resumes the monitoring
  • @AQIDuck hello says hi
  • @AQIDuck reload reolads the config from the channel topic (this should happen automatically anyway)

To find your PurpleAir sensor ID:

  • On the PurpleAir map, click on the sensor you're interested in
  • The sensor ID will be in the URL: How to find PurpleAir ID from URL
  • At the bottom of the widget with the air quality, hover over "Get This Widget"
  • The ID in the div of the widget also contains the sensor ID How to find PurpleAir ID from widget

aqiduck's People

Contributors

alenia avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

daniel-ziegler

aqiduck's Issues

Use Groups from the PurpleAir API

Report certain errors to slack

Some errors should post a slack message

  • If there are API issues when reporting for the first time, post a message (probably depends on the error code from PA)
  • If the JSON has unknown fields, post a message
    Future:
  • If there are repeated issues monitoring the same endpoint, post a message

Let user know if AQI thresholds are set up correctly

I think right now that if the thresholds aren’t properly named (i.e. if the JSON keys are spelled wrong) the user won’t know that the bot isn’t monitoring anything. When config is loaded/reloaded, just announce what monitoring is going on

Talk to the bot in order to CRUD sensors

This should also ideally change the channel topic

Comands:

  • monitor [SensorName] AQI 40-50 "OK I'll let you know if the [SensorName] AQI drops below 40 or above 50"
  • add sensor NAME ID (defaults to purpleair)
  • remove sensor NAME
  • reload re-initializes all sensors from the JSON

Eventually have conversations like:

  • add sensor "By ID or by zip code?" ID "What is the sensor ID?" 12345 "What do you want to call the sensor?" name "Alright we're now set up in this channel to read from sensor 12345" (changes channel topic)

Monitor temperature

Basic: Set temperature thresholds to monitor
Advanced: Monitor comparison in temperature between two sensors.

Raw temperature from purple air sensor is too high

Subtract 8 from the results when reporting them

We’ve found that a correction of 8°F correlates closely to the ambient temperature, while a 4% correction correlates closely to the ambient humidity

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.