Portainer
The Portainer integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] is used as an interface to the Portainer API. Portainer is a lightweight management UI that allows you to easily manage your Docker containers, images, networks, and volumes. It works on every Docker host or Swarm cluster.
The Portainer API provides a way to manage Docker containers, images, networks, and volumes. It allows you to interact programmatically with your Docker host or Swarm cluster.
Prerequisites
Before you can configure Portainer within Home Assistant, you need a few things:
- have Portainer installed and a user with administrator rights on Portainer.
- An access token.
Create a Portainer Access Token by following these steps:
- Log in to your Portainer instance.
- To create an access token, follow the steps in the Portainer documentation.
- Copy the generated Access Token and store it somewhere safe, you will need it in the next steps.
Configuration
To add the Portainer service to your Home Assistant instance, use this My button:
Manual configuration steps
If the above My button doesn’t work, you can also perform the following steps manually:
-
Browse to your Home Assistant instance.
-
In the bottom right corner, select the
Add Integration button. -
From the list, select Portainer.
-
Follow the instructions on screen to complete the setup.
Supported functionality
There is currently support for the following device types within Home Assistant:
Binary sensors
- Status: Reports whether a container is running.
- Out of memory: Reports a problem when the container was stopped because it ran out of memory. It resets when the container starts again.
Buttons
- Restart container: Restarts the container.
- Pause container: Pauses the container.
- Resume container: Resumes the container.
- Recreate container: Recreates the container by pulling the latest tagged image.
- Pull image: Downloads the container’s configured image without recreating or restarting the container, so a later recreation can use the downloaded image. The container keeps running the old image until it is recreated, so its image update stays available until then. Disabled by default. Images from a private registry can’t be pulled this way; recreate the container instead.
- Prune unused images: Removes unused Docker images from the endpoint.
- Prune unused volumes: Removes unused Docker volumes from the endpoint.
- Prune build cache: Removes the unused Docker build cache from the endpoint.
- Prune unused networks: Removes Docker networks from the endpoint that aren’t used by any container. The default Docker networks are kept.
- Update stack: Pulls the latest images and redeploys the stack. Stacks deployed from a Git repository are redeployed from that repository. The stack keeps its environment variables and settings. Not available for Kubernetes stacks.
Events
-
Docker event: Fires when Portainer reports a Docker container lifecycle event, such as
start,stop,restart,die,pause,unpause,kill,oom, orupdate, and when the container’s health check status changes (health_status_healthy,health_status_unhealthy, orhealth_status_starting).
Sensors
Container sensors
-
State: Current container state (such as
running,exited,paused). - Image: The Docker image the container is based on.
- CPU usage total: Total CPU time consumed by the container.
- Memory usage: Current memory usage of the container.
- Memory usage percentage: Memory usage as a percentage of the container’s limit.
- Memory limit: Memory limit configured for the container.
- Started: When the container was last started.
- Restart count: How often Docker restarted the container, for example, because of its restart policy.
-
Last exit code: The exit code of the container’s last run, for example,
137when it was killed. Only reported while the container is not running, because Docker resets it to0when the container starts. Disabled by default.
Endpoint sensors
- Docker version: Docker engine version running on the host.
- API version: Docker API version on the host.
- Kernel version: Kernel version of the host operating system.
- Operating system: Operating system running on the host.
- Total memory: Total memory available on the host.
- Total CPU: Total CPU cores available on the host.
- Containers running: Number of currently running containers.
- Containers stopped: Number of stopped containers.
- Containers paused: Number of paused containers.
- Container count: Total number of containers on the endpoint.
- Image count: Total number of Docker images.
Disk space sensors
These sensors are disabled by default, because calculating them can take a long time on slower hardware (see Data updates). This also applies to existing installations: when you upgrade, the integration disables these sensors. Enable the ones you need. Enabled disk space sensors update every 30 minutes.
- Container disk usage total size: Total disk space used by containers.
- Container disk usage reclaimable: Disk space used by containers that are not running.
- Image disk usage total size: Total disk space used by images.
- Image disk usage reclaimable: Disk space used by images that no container uses.
- Volume disk usage total size: Total disk space used by volumes.
- Volume size: Disk space used by a single volume. Unknown for volumes whose driver doesn’t report a size.
Stack sensors
-
Status: Whether the stack is
activeorinactive. -
Type: The stack type:
Compose,Swarm, orKubernetes. - Container count: Number of containers belonging to the stack.
- Last deployed: When the stack was last deployed or updated, including redeploys and Git auto-updates. For a stack that was never updated, this is when it was created.
Switches
- Container: Starts or stops an individual Docker container.
- Stack: Starts or stops all containers in a stack.
Updates
- Image update available: Shows whether a newer image is available for a container. Installing the update pulls the latest image, showing its download progress, and then recreates the container with it. For images from a private registry, Portainer pulls the image itself and no progress is shown.
- Update: Shows the running Portainer version and the latest release, with a link to its release notes. Portainer itself can’t be updated from Home Assistant.
List of actions
The Portainer integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] provides the following actions. Each link below opens a dedicated page with examples, parameters, and a step-by-step UI walkthrough.
-
Prune build cache (
portainer.prune_build_cache) Removes the Docker build cache from a Portainer endpoint. -
Prune unused images (
portainer.prune_images) Removes unused images from a Portainer endpoint. -
Recreate container (
portainer.recreate_container) Recreates a container on a Portainer endpoint.
For an overview of every action across all integrations, see the actions reference.
Examples
The following examples show how to use the Portainer integration in Home Assistant automations. These examples are just a starting point, and you can use them as inspiration to create your own automations.
Notify when a container went down
The following example sends a notification to your mobile device when a container went down.
automation:
- alias: "Container went down"
triggers:
- trigger: state
entity_id:
- sensor.container_state
to:
- exited
actions:
- action: notify.send_message
target:
entity_id: notify.my_device
data:
title: "Container alert"
message: "Container went down!"
Supported devices
The integration creates one device for the Portainer server and one device per Portainer endpoint (Docker host). Containers and stacks appear as child devices under their endpoint. If a container belongs to a stack, it is nested under that stack instead.
Portainer server
The Portainer instance itself is a device, exposing the Update entity for Portainer.
Endpoints
Each Docker host managed by Portainer is represented as an endpoint device, exposing host-level information such as Docker version, memory, CPU, and container counts.
Containers
Each Docker container is a child device under its endpoint or stack. Container devices expose resource usage sensors, a status binary sensor, a restart button, and a switch to start or stop the container.
Stacks
Each Docker Compose or Swarm stack is a child device under its endpoint. Stack devices expose a status sensor, a type sensor, a container count sensor, a last deployed sensor, a switch to start or stop the entire stack, and a button to update it.
Docker API Engine needs to be equal to or above version 1.44. Older versions are deprecated.
Data updates
The integration normally updates every 60 seconds. The Portainer version is checked every 6 hours, because Portainer looks up the latest release on GitHub for every check. For more detailed steps on how to define a custom polling interval, follow the procedure below.
The disk space sensors update every 30 minutes, and only for endpoints with at least one of them enabled. To calculate them, Docker adds up every file in every volume, which can take minutes on slower hardware.
Defining a custom polling interval
If you want to define a specific interval at which your device is being polled for data, you can disable the default polling interval and create your own polling automation.
To turn off the default polling and create your own polling automation, follow these steps:
- Go to Settings > Devices & services, and select your integration.
- On the integration entry, select the three dots
menu, and then select System options. - Turn off Enable polling for changes, and then select Update.
- If Home Assistant asks you to restart, restart it.
- Go to Settings > Automations & scenes, and select Create automation > Create new automation.
- Add the triggers and conditions for when you want to poll for data.
- Select Add action, select By type, select Perform action, and then select + next to Perform action.
- Under Action, search for and select the Update entity action.
- Under Entities to update, select the entities you want to poll.
- You can only select entities. Areas, devices, and labels aren’t supported.
- Select Save.
Many integrations update their data at most once every 10 seconds. If you poll more often, Home Assistant waits until the 10 seconds have passed before it updates the data again.
Known limitations
Currently, the integration does not support stacks or Edge computing.
Troubleshooting
Sensors are unavailable or the integration times out
Symptom: Timeouts when the integration updates
The integration fails to update, or you see timeout errors in the logs such as:
Timed out fetching DF data for endpointTimeout fetching portainer data
Description
Docker calculates the disk space sensors by adding up every file in every volume. On lower-end hardware with slower disks, such as a Raspberry Pi, this can take long enough to cause timeouts.
Resolution
- Disable the disk space sensors of the endpoint. Once none of them are enabled, the integration stops fetching disk space data for that endpoint.
- If timeouts persist, reduce the load by setting a longer polling interval.
Removing the integration
This integration follows standard integration removal.
To remove an integration instance from Home Assistant
- Go to Settings > Devices & services and select the integration card.
- Next to the entry you want to remove, select the three dots
menu. Then, select Delete. - Depending on the integration, the entries are listed under one of the following headings:
- Devices
- Hubs
- Services
- Integration entries
- Depending on the integration, the entries are listed under one of the following headings:
- To confirm, select Delete.
- Home Assistant also deletes the devices and entities of the entry.
- If Home Assistant asks you to restart, restart Home Assistant.
- If Home Assistant asks whether to also delete the application credentials, select Remove or Keep.
- If you keep them, Home Assistant uses them automatically when you add the integration again.
- To delete them later, refer to Deleting application credentials.
After removing the integration, consider deleting the Portainer access token.