Skip to main content

DigitalOcean smart home integration, free and open source

DigitalOcean integration for Gladys Assistant

DigitalOcean: droplets (status, IP), usage and balance, alerts, uptime checks; power on.

This integration reads your DigitalOcean account through its official API v2: your droplets (status, public IPv4), the usage and balance of the month, the number of alert policies enabled and the state of your uptime checks. It can power a droplet on; shutting down, forcing the power off and rebooting are off until you allow them. It never creates, resizes nor deletes anything.

Unofficial integration, not affiliated with DigitalOcean. Never tested with a real device: written and tested from the official API documentation, against a simulated API, without a real account.

Costs​

The DigitalOcean API is free, but your account is billed for your resources. This integration creates nothing and resizes nothing. A droplet powered on again uses its outbound traffic as before (billed beyond its allowance). Beware: a droplet turned off is still billed (only deleting it stops the billing, and the integration never deletes anything).

Token​

In the DigitalOcean control panel: API, Tokens, Generate New Token.

  • Read only (recommended): the Read scope. Everything is read; the buttons answer that the token is read only.
  • For the buttons: custom scopes with droplet:read and droplet:update, plus account:read, billing:read, monitoring:read and uptime:read to read the rest. Add neither droplet:create, nor droplet:delete, nor droplet:admin: the integration does not need them.

The token is kept by Gladys in its database, never shown again, sent only to DigitalOcean (api.digitalocean.com, certificate checked). It appears in no log, status nor file of the integration.

If DigitalOcean refuses the token (HTTP 401 on the droplet list: revoked, expired, mistyped), the integration stops and does not try it again by itself, even after a restart, until you save a new token or click Test the connection. A refusal on another read (billing, alerts, uptime checks) stops nothing: that read is tried again later, more and more spaced (up to 1 h), and the status says so.

Devices​

From the Discovery:

DeviceFeatures
DigitalOcean accountUsage this month, balance this month, account balance (US dollars), alert policies enabled, account status
A dropletRunning (yes/no), status, public IPv4; Power on, Shut down, Force power off, Reboot buttons
An uptime checkUp (yes/no), status, uptime over 30 days (%)
  • Ids: the account by the id of its team (or of the account without a team), a droplet by its number, an uptime check by its DigitalOcean id.
  • The usage and balance are those DigitalOcean computes (generated_at); older than 48 h, they are not published. Read once an hour.
  • The alert policies of DigitalOcean (CPU, memory, disk...) expose no "firing" state in the API: only how many are enabled is read (their e-mails and Slack URLs are never kept). The up / down state comes from the uptime checks: down as soon as one region sees it down.
  • An unknown value (empty, unreadable, a droplet being created) is never published as 0.
  • GPU droplets are not listed (the API keeps them apart); beyond 1000 droplets, the others are left out and the status says so.

Buttons​

They are buttons, never switches: a "turn everything off" of a voice assistant or a scene does not reach them.

  • Power on: allowed without an option.
  • Shut down (shutdown, clean), Force power off (power_off, like pulling the plug), Reboot (reboot, clean): each one off by default, to allow in the configuration.

For each press:

  1. the option is read again (an option turned off takes effect at once, even during a read or a command);
  2. the droplet is read again; the decision is made on that read (already in the state asked: nothing sent; locked by DigitalOcean or status unknown: refused);
  3. everything is checked again right before sending (option, pause, quota, a newer stop of the same droplet, deadline);
  4. the request leaves within 3.5 s of the press or not at all;
  5. a command is shown as done only once a later read shows it (Power on: droplet running; Shut down and Force power off: droplet off; Reboot: action completed then droplet running). The reads follow at 5 s, 20 s, 60 s (180 s for Shut down, 10/30/90 s for Reboot). Without a clear answer, the command is "sent, without confirmation" and is never sent again by itself (a Reboot sent so cannot be confirmed: the droplet runs either way; check it in the control panel).

Safeguards: one command per droplet per 15 s; one at a time per droplet; after Shut down or Force power off, Power on of that droplet is refused for 1 min (a guard written to /data before sending; if /data cannot write it, nothing is sent), also after a restart; a stop cancels a Power on of the same droplet not sent yet. The result of each command shows in the status of the integration for 10 min.

Reasons Shut down or Force power off is refused, nothing being sent: option off, integration not configured, token refused, pause asked by DigitalOcean (429 or 5xx), quota of the token used up, another command running or less than 15 s since the previous one on that droplet, droplet not found, unreadable, locked or not running, /data not keeping the guard, token changed during the command, DigitalOcean too slow (beyond 3.5 s). With a Read token, DigitalOcean refuses by itself (HTTP 403).

Reads and quotas​

  • The droplets: at each refresh (120 s by default, 60 to 3600 s), never sooner, even after a restart or a click on Scan; the account every 6 h; the billing and the alert policies every hour; the list of uptime checks every 10 min, and the state of up to 10 of them at each refresh, in turn.
  • The token allows 5,000 requests per hour (250 per minute), shared with your other tools. The integration follows the ratelimit-* headers of every answer: under 20 % left, it reads only the droplets; under 25 requests, it waits for DigitalOcean to free some (by its clock, 1 min to 1 h).
  • A 429 or a 5xx error pauses reads and commands (the Retry-After delay, else until the ratelimit-reset of DigitalOcean (1 h at most), at least 1 min, doubled at each repeated failure, 6 h at most), kept in /data.
  • No redirection is followed; answers are bounded in size and time.

Troubleshooting​

  • "DigitalOcean refused the token": create a new one, save it (or click Test).
  • "Not read: balance (billing:read)": the token lacks this scope; add it or ignore.
  • A button answers "token without the droplet:update scope": a Read token, on purpose or not.
  • "Shut down: not applied yet": a clean shutdown depends on the system of the droplet; DigitalOcean only makes sure the request is issued. Check in the control panel, or use Force power off if you allowed it.

Configuration settings​

These are the settings DigitalOcean asks for in its configuration screen in Gladys.

SettingTypeRequiredDescription
How it workssectionNoGladys reads your DigitalOcean account through its official API v2 with a personal access token: the droplets (status, public IPv4), the usage and balance of the month, the number of alert policies enabled and the state of your uptime checks, as devices to add from the Discovery. A droplet can be powered on; shutting down, forcing the power off and rebooting are each off until you allow them below. Nothing is ever created, resized nor deleted. The API itself is free, but your account is billed: a droplet turned off is still billed. Never tested with a real device. Unofficial integration, not affiliated with DigitalOcean.
DigitalOcean API tokensecretYesControl panel, API, Tokens, Generate New Token. A Read token is enough to read everything; the buttons then answer that the token is read only. To use the buttons, a custom token with droplet:read and droplet:update (plus account:read, billing:read, monitoring:read and uptime:read to read the rest). Kept by Gladys in its database, never shown again, sent only to DigitalOcean (api.digitalocean.com). If DigitalOcean refuses it, Gladys stops until you save another one or click Test.
Refresh (seconds)numberNoHow often Gladys reads the droplets (one request per 200 droplets, plus up to 10 uptime checks in turn). The balance and the alert policies are read once an hour. The token allows 5,000 requests per hour, shared with your other tools. 60 to 3600 seconds.
Droplet buttonssectionNoPower on needs no option. The three buttons below can stop a service you host: each one is off by default, decided on a fresh read of the droplet, checked again right before sending, one command per droplet per 15 s, and Power on is refused for 1 min after a shutdown. A command is shown as done only once a later read shows it.
Allow shutting droplets downbooleanNoOff by default. On: the Shut down button asks the system of a running droplet to shut down cleanly (DigitalOcean only makes sure the request is issued). A droplet turned off is still billed.
Allow forcing the power offbooleanNoOff by default. On: the Force power off button cuts the droplet off at once, like pulling the plug (data not saved is lost).
Allow rebooting dropletsbooleanNoOff by default. On: the Reboot button asks the system of a running droplet to restart cleanly.
Language of names and messagesselectNoThe names of the devices and features at their creation, the statuses and the messages of the buttons.

How to install DigitalOcean in Gladys​

  1. In Gladys, open Integrations: DigitalOcean appears in the catalog, next to the native integrations, with a community badge.
  2. Click Install. Gladys pulls the Docker image (ghcr.io/lm1lc3n7/gladys-digitalocean:0.1.1), starts it in a sandbox isolated from the core, and generates the integration's interface (devices, discovery and configuration).
  3. Open the Configuration screen of the integration, fill in the settings, and save.
  4. You can also install it directly from its repository URL: https://github.com/LM1LC3N7/gladys-digitalocean.

DigitalOcean requires Gladys >=5.1.0. The catalog inside Gladys refreshes every hour, so a new version becomes available at most one hour after its release.

Not running Gladys yet? It is free and open source: follow the installation guide to get started.

About external integrations​

DigitalOcean is an external integration: a community integration packaged as a Docker container and published on GitHub, that Gladys installs in one click and runs in a sandbox isolated from its core. It is published and maintained by LM1LC3N7, not by the Gladys core team.

Subscribe to the Gladys Assistant newsletter

A few emails per month about new releases and project news. Sent by Pierre-Gilles Leymarie, founder of the project. Unsubscribe anytime 🙂