Skip to content

A Slackbot on Cloudflare set to notify when Govee thermometer reaches certain temperatures.

Notifications You must be signed in to change notification settings

paulathevalley/commons-thermometer

Repository files navigation

commons-thermometer

A thermometer with wifi. An amateur cloudflare setup. A Slackbot named Thermo-bot.

thermobot

Local development

Create a .dev.vars with your secrets including access to Govee, GOVEE_API_KEY, and Slack, SLACK_TOKEN, BOT_USER_OAUTH_TOKEN. A matching encrypted variable should be created for the worker on the Cloudflare dashboard. Wrangler Environments

nvm use stable
npm install
npm run dev

To test scheduled() handlers in local development:

npx wrangler dev --test-scheduled

curl "http://localhost:8787/__scheduled?cron=*+*+*+*+*"

References:

Govee API

The Govee Wi-Fi Thermo-Hygrometer has an API available to use for non-commercial purposes: https://developer.govee.com/reference/get-you-devices

The thermometer returns a sensorTemperature and a sensorHumidity object with values. Currently the temperature is in Fahrenheit.

The API is subject to change without notice.

References:

Slack Web API

The slack web API does not currently support Cloudflare workers: slackapi/node-slack-sdk#1335

A third-party library, slack-web-api-client, does support Cloudflare workers: https://github.com/seratch/slack-web-api-client so we are using this instead.

References:

Cloudflare Workers

We created a worker following the Guide on Cloudflare.

We are using Wrangler to test locally and deploy to Cloudflare.

We are using two handlers for our Slackbot: fetch() and scheduled(). When a human uses the bot’s slash command, the fetch handler will run. We set up Cron Triggers on the Cloudflare account dashboard that will run the scheduled handler at certain intervals of time. Ideally the wrangler.toml file here would be in sync with the triggers set on Cloudflare.

We are using "Service Worker Syntax" but may want to migrate to es modules someday: https://developers.cloudflare.com/workers/reference/migrate-to-module-workers/

About

A Slackbot on Cloudflare set to notify when Govee thermometer reaches certain temperatures.

Resources

Stars

Watchers

Forks