Rest Command > Portainer

Bonjour à tous,

Depuis 2 jours je galère avec un Post Rest_command. En effet, je tente d’implémenter le start/stop d’un container Docker via les API de portainer.

Le fonctionnement est assez simple : faire un post sur le container en passant l’api key.
J’ai testé l’API sur postman en passant la clef et l’url et j’arrive bien à start/stop mon conteneur. Cool !

Du coup, je passe sur HA et je créé une rest_command que je pense similaire au paramétrage postman :

rest_command:
  zoffline_start_container:
    url: https://192.168.1.30:9443/api/endpoints/2/docker/containers/259b7beafaa4066ec8537f7029e8bf1b034fd9388ff9821ebbe5d7d0c3ab52df/start
    method: POST
    headers:
       x-api-key: "ptr_rEgEuajyqUuN+fVuDtajCH8FM+ph2rIiP/9jEHAY6hs="
    payload: "{}"

Cependant, rien ne se passe lorsque je lance le service et j’ai cette erreur dans les logs :
Error while executing automation automation.docker_zoffline_eteindre: Client error occurred when calling resource 'https://192.168.1.30:9443/api/endpoints/2/docker/containers/259b7beafaa4066ec8537f7029e8bf1b034fd9388ff9821ebbe5d7d0c3ab52df/stop'

Avez vous une idée car je deviens fou.

Merci

Salut

L’erreur ne correspond pas à ton rest_command.

Met ça dans ton configuration.yaml et redémarre HA.

logs:
        homeassistant.components.rest_command: debug

Et teste avec « services » dans « outils de développement » :
image

Ça m’ouvre des perspectives.
On peut faire un update d’un docker (portainer) avec cette solution ?

ça plutot ? :slight_smile:

logger:  
  default: info
  logs:
    homeassistant.components.rest_command: debug
    homeassistant.components.rest.data: debug

le log n’est pas plus bavard dans les journaux :frowning:

Enregistreur: homeassistant.components.automation.docker_zoffline_allumer
Source: components/automation/__init__.py:687
intégration: Automatisation ([documentation](https://www.home-assistant.io/integrations/automation), [problèmes](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+automation%22))
S'est produit pour la première fois: 13:45:00 (1 occurrences)
Dernier enregistrement: 13:45:00

Error while executing automation automation.docker_zoffline_allumer: Client error occurred when calling resource 'https://192.168.1.30:9443/api/endpoints/2/docker/containers/259b7beafaa4066ec8537f7029e8bf1b034fd9388ff9821ebbe5d7d0c3ab52df/start'
Enregistreur: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/connection.py:300
intégration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [problèmes](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
S'est produit pour la première fois: 13:53:20 (2 occurrences)
Dernier enregistrement: 13:53:34

[140512406148800] Error handling message: Client error occurred when calling resource 'https://192.168.1.30:9443/api/endpoints/2/docker/containers/259b7beafaa4066ec8537f7029e8bf1b034fd9388ff9821ebbe5d7d0c3ab52df/start' (home_assistant_error) Cedric from 92.103.210.204 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36)

et via les outils de dev

Regarde du côté de Portainer, si tu vois quelque chose.

Auto reply :slight_smile:

verify_ssl: false
Car pas de certif valid sur cette machine

il faut regarder la doc des API => https://docs.portainer.io/api/examples

pour aller plus loin avec les API, je voulais tenter un GET sur portainer.

[
    {
        "Command": "/init",
        "Created": 1710277771,
        "FinishedAt": 1711005617,
        "HostConfig": {
            "NetworkMode": "domotique"
        },
        "Id": "f28aacbe3520e2110ef6b0b29cfca66207427559ad34bb1fbe157fe68d9d7300",
        "Image": "ghcr.io/blakeblackshear/frigate:stable",
        "ImageID": "sha256:a476481a2855d9a36cdf12083da58e89fa1b20d6d84630a05e4e9c1d67182179",
        "Labels": {},
        "Mounts": [
            {
                "Destination": "/config",
                "Mode": "rw",
                "Propagation": "rprivate",
                "RW": true,
                "Source": "/volume1/docker/frigate/config",
                "Type": "bind"
            },
            {
                "Destination": "/media/frigate",
                "Mode": "rw",
                "Propagation": "rprivate",
                "RW": true,
                "Source": "/volume1/docker/frigate/media",
                "Type": "bind"
            }
        ],
        "Names": [
            "/ghcr.io-blakeblackshear-frigate1"
        ],
        "NetworkSettings": {
            "Networks": {
                "bridge": {
                    "Aliases": null,
                    "DriverOpts": null,
                    "EndpointID": "8999bea4fc1aab7c478f69e3ad32cfcf600718383ec034f3163849760f112fe0",
                    "Gateway": "172.17.0.1",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "IPAMConfig": null,
                    "IPAddress": "172.17.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "Links": null,
                    "MacAddress": "02:42:ac:11:00:03",
                    "NetworkID": "c4d77eb7d45cdebef2a9771b0e44e8a0930a037efa7fdb1ff81bfed44f7fdb57"
                },
                "domotique": {
                    "Aliases": null,
                    "DriverOpts": null,
                    "EndpointID": "0171f7f652987898fa69a84149815e712fb19faa55b4bdd8ede2d3fbbeeb4c77",
                    "Gateway": "172.19.0.1",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "IPAMConfig": null,
                    "IPAddress": "172.19.0.4",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "Links": null,
                    "MacAddress": "02:42:ac:13:00:04",
                    "NetworkID": "dc489bbc3f634dbc781c4feeac4d1e27607bfa46b19cd05e1c07430feec99a2a"
                }
            }
        },
        "Ports": [
            {
                "IP": "0.0.0.0",
                "PrivatePort": 1935,
                "PublicPort": 1935,
                "Type": "tcp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 5000,
                "PublicPort": 6545,
                "Type": "tcp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 8554,
                "PublicPort": 8554,
                "Type": "tcp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 8555,
                "PublicPort": 8555,
                "Type": "tcp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 8555,
                "PublicPort": 8555,
                "Type": "udp"
            }
        ],
        "StartedAt": 1711017210,
        "State": "running",
        "Status": "Up 9 hours (healthy)"
    },
    {
        "Command": "/portainer",
        "Created": 1709756643,
        "FinishedAt": 1710838206,
        "HostConfig": {
            "NetworkMode": "default"
        },
        "Id": "cca7e43035388906855c95f0b31545ce5b433fffd376221e030e27d8e4997f6b",
        "Image": "portainer/portainer-ce:latest",
        "ImageID": "sha256:1a0fb356ea35830bad2a93aea5a72c88385b3505490cf035a575122bbe094a81",
        "Labels": {
            "com.docker.desktop.extension.api.version": ">= 0.2.2",
            "com.docker.desktop.extension.icon": "https://portainer-io-assets.sfo2.cdn.digitaloceanspaces.com/logos/portainer.png",
            "com.docker.extension.additional-urls": "[{\"title\":\"Website\",\"url\":\"https://www.portainer.io?utm_campaign=DockerCon&utm_source=DockerDesktop\"},{\"title\":\"Documentation\",\"url\":\"https://docs.portainer.io\"},{\"title\":\"Support\",\"url\":\"https://join.slack.com/t/portainer/shared_invite/zt-txh3ljab-52QHTyjCqbe5RibC2lcjKA\"}]",
            "com.docker.extension.detailed-description": "<p data-renderer-start-pos=\"226\">Portainer&rsquo;s Docker Desktop extension gives you access to all of Portainer&rsquo;s rich management functionality within your docker desktop experience.</p><h2 data-renderer-start-pos=\"374\">With Portainer you can:</h2><ul><li>See all your running containers</li><li>Easily view all of your container logs</li><li>Console into containers</li><li>Easily deploy your code into containers using a simple form</li><li>Turn your YAML into custom templates for easy reuse</li></ul><h2 data-renderer-start-pos=\"660\">About Portainer&nbsp;</h2><p data-renderer-start-pos=\"680\">Portainer is the worlds&rsquo; most popular universal container management platform with more than 650,000 active monthly users. Portainer can be used to manage Docker Standalone, Kubernetes, Docker Swarm and Nomad environments through a single common interface. It includes a simple GitOps automation engine and a Kube API.&nbsp;</p><p data-renderer-start-pos=\"1006\">Portainer Business Edition is our fully supported commercial grade product for business-wide use. It includes all the functionality that businesses need to manage containers at scale. Visit <a class=\"sc-jKJlTe dPfAtb\" href=\"http://portainer.io/\" title=\"http://Portainer.io\" data-renderer-mark=\"true\">Portainer.io</a> to learn more about Portainer Business and <a class=\"sc-jKJlTe dPfAtb\" href=\"http://portainer.io/take-3?utm_campaign=DockerCon&amp;utm_source=Docker%20Desktop\" title=\"http://portainer.io/take-3?utm_campaign=DockerCon&amp;utm_source=Docker%20Desktop\" data-renderer-mark=\"true\">get 3 free nodes.</a></p>",
            "com.docker.extension.publisher-url": "https://www.portainer.io",
            "com.docker.extension.screenshots": "[{\"alt\": \"screenshot one\", \"url\": \"https://portainer-io-assets.sfo2.digitaloceanspaces.com/screenshots/docker-extension-1.png\"},{\"alt\": \"screenshot two\", \"url\": \"https://portainer-io-assets.sfo2.digitaloceanspaces.com/screenshots/docker-extension-2.png\"},{\"alt\": \"screenshot three\", \"url\": \"https://portainer-io-assets.sfo2.digitaloceanspaces.com/screenshots/docker-extension-3.png\"},{\"alt\": \"screenshot four\", \"url\": \"https://portainer-io-assets.sfo2.digitaloceanspaces.com/screenshots/docker-extension-4.png\"},{\"alt\": \"screenshot five\", \"url\": \"https://portainer-io-assets.sfo2.digitaloceanspaces.com/screenshots/docker-extension-5.png\"},{\"alt\": \"screenshot six\", \"url\": \"https://portainer-io-assets.sfo2.digitaloceanspaces.com/screenshots/docker-extension-6.png\"},{\"alt\": \"screenshot seven\", \"url\": \"https://portainer-io-assets.sfo2.digitaloceanspaces.com/screenshots/docker-extension-7.png\"},{\"alt\": \"screenshot eight\", \"url\": \"https://portainer-io-assets.sfo2.digitaloceanspaces.com/screenshots/docker-extension-8.png\"},{\"alt\": \"screenshot nine\", \"url\": \"https://portainer-io-assets.sfo2.digitaloceanspaces.com/screenshots/docker-extension-9.png\"}]",
            "io.portainer.server": "true",
            "org.opencontainers.image.description": "Docker container management made simple, with the world’s most popular GUI-based container management platform.",
            "org.opencontainers.image.title": "Portainer",
            "org.opencontainers.image.vendor": "Portainer.io"
        },
        "Mounts": [
            {
                "Destination": "/data",
                "Mode": "rw",
                "Propagation": "rprivate",
                "RW": true,
                "Source": "/volume1/docker/portainer-ce",
                "Type": "bind"
            },
            {
                "Destination": "/var/run/docker.sock",
                "Mode": "rw",
                "Propagation": "rprivate",
                "RW": true,
                "Source": "/var/run/docker.sock",
                "Type": "bind"
            }
        ],
        "Names": [
            "/portainer"
        ],
        "NetworkSettings": {
            "Networks": {
                "bridge": {
                    "Aliases": null,
                    "DriverOpts": null,
                    "EndpointID": "2c7eae4134ba7327443cda427f0c01f4bcef3d74b5d1076bbe5117368cf0ec73",
                    "Gateway": "172.17.0.1",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "IPAMConfig": null,
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "Links": null,
                    "MacAddress": "02:42:ac:11:00:02",
                    "NetworkID": "c4d77eb7d45cdebef2a9771b0e44e8a0930a037efa7fdb1ff81bfed44f7fdb57"
                }
            }
        },
        "Ports": [
            {
                "IP": "0.0.0.0",
                "PrivatePort": 8000,
                "PublicPort": 8000,
                "Type": "tcp"
            },
            {
                "PrivatePort": 9000,
                "Type": "tcp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 9443,
                "PublicPort": 9443,
                "Type": "tcp"
            }
        ],
        "StartedAt": 1710838371,
        "State": "running",
        "Status": "Up 2 days"
    },
    {
        "Command": "docker-entrypoint.sh /sbin/tini -- node index.js",
        "Created": 1709755261,
        "FinishedAt": 1710838668,
        "HostConfig": {
            "NetworkMode": "domotique"
        },
        "Id": "7542deb983aba7765c0b7d9aae7b056481afc409264626490d5f3a04cb965e8f",
        "Image": "koenkk/zigbee2mqtt:latest",
        "ImageID": "sha256:678f628fa4b3a9a1de98971153055557b351a83d6d3a543e30e00808c592c987",
        "Labels": {},
        "Mounts": [
            {
                "Destination": "/app/data",
                "Mode": "rw",
                "Propagation": "rprivate",
                "RW": true,
                "Source": "/volume1/docker/zigbee2mqtt/app",
                "Type": "bind"
            }
        ],
        "Names": [
            "/koenkk-zigbee2mqtt1"
        ],
        "NetworkSettings": {
            "Networks": {
                "domotique": {
                    "Aliases": null,
                    "DriverOpts": null,
                    "EndpointID": "3d5c2d9a80c0b3ea067d95448f4bfc9b8afe7347cd07c8f658c417ed274d5362",
                    "Gateway": "172.19.0.1",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "IPAMConfig": null,
                    "IPAddress": "172.19.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "Links": null,
                    "MacAddress": "02:42:ac:13:00:02",
                    "NetworkID": "dc489bbc3f634dbc781c4feeac4d1e27607bfa46b19cd05e1c07430feec99a2a"
                }
            }
        },
        "Ports": [
            {
                "IP": "0.0.0.0",
                "PrivatePort": 8080,
                "PublicPort": 8080,
                "Type": "tcp"
            }
        ],
        "StartedAt": 1710838677,
        "State": "running",
        "Status": "Up 2 days"
    },
    {
        "Command": "python zwift-offline/standalone.py",
        "Created": 1709754933,
        "FinishedAt": 1710882863,
        "HostConfig": {
            "NetworkMode": "bridge"
        },
        "Id": "259b7beafaa4066ec8537f7029e8bf1b034fd9388ff9821ebbe5d7d0c3ab52df",
        "Image": "zoffline/zoffline:latest",
        "ImageID": "sha256:a85ae73ef03ccb1ba8a96b6aa163a3c8e7e3831462249d035d00a7b9cbaf4d80",
        "Labels": {
            "org.opencontainers.image.created": "2024-01-31T20:04:51.424Z",
            "org.opencontainers.image.description": "Use Zwift offline",
            "org.opencontainers.image.licenses": "AGPL-3.0",
            "org.opencontainers.image.revision": "2ea1b51b648f65f52f793b4a8cb2c117277eba72",
            "org.opencontainers.image.source": "https://github.com/zoffline/zwift-offline",
            "org.opencontainers.image.title": "zwift-offline",
            "org.opencontainers.image.url": "https://github.com/zoffline/zwift-offline",
            "org.opencontainers.image.version": "zoffline_1.0.125438"
        },
        "Mounts": [
            {
                "Destination": "/usr/src/app/zwift-offline/storage",
                "Mode": "rw",
                "Propagation": "rprivate",
                "RW": true,
                "Source": "/volume1/docker/zoffline/storage",
                "Type": "bind"
            }
        ],
        "Names": [
            "/zoffline-zoffline"
        ],
        "NetworkSettings": {
            "Networks": {
                "zwift": {
                    "Aliases": null,
                    "DriverOpts": null,
                    "EndpointID": "9d592071d4eba5243ef8018bc64e62bf613ddec745f34d0f702e399da1319f61",
                    "Gateway": "172.18.0.1",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "IPAMConfig": null,
                    "IPAddress": "172.18.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "Links": null,
                    "MacAddress": "02:42:ac:12:00:02",
                    "NetworkID": "0f8509741e12aae60c49ae70e34bcce20d199cd9f51451159bcad7ce1db47c00"
                }
            }
        },
        "Portainer": {
            "ResourceControl": {
                "Id": 1,
                "ResourceId": "259b7beafaa4066ec8537f7029e8bf1b034fd9388ff9821ebbe5d7d0c3ab52df",
                "SubResourceIds": [],
                "Type": 1,
                "UserAccesses": [],
                "TeamAccesses": [],
                "Public": false,
                "AdministratorsOnly": true,
                "System": false
            }
        },
        "Ports": [
            {
                "IP": "0.0.0.0",
                "PrivatePort": 3024,
                "PublicPort": 49155,
                "Type": "udp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 3025,
                "PublicPort": 49156,
                "Type": "tcp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 443,
                "PublicPort": 49157,
                "Type": "tcp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 53,
                "PublicPort": 49156,
                "Type": "udp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 80,
                "PublicPort": 49158,
                "Type": "tcp"
            }
        ],
        "StartedAt": 1711050646,
        "State": "running",
        "Status": "Up 6 minutes"
    },
    {
        "Command": "/docker-entrypoint.sh /usr/sbin/mosquitto -c /mosquitto/config/mosquitto.conf",
        "Created": 1682239002,
        "FinishedAt": 1710838215,
        "HostConfig": {
            "NetworkMode": "domotique"
        },
        "Id": "5e35d646d3080215e81335b09c2aaf2e20d8c02fca2a269b203e972a8c6799b3",
        "Image": "eclipse-mosquitto:latest",
        "ImageID": "sha256:35a004f35c819eef86607c58d2cfb2dd89a63dd86fa6d9b117650e2baded82c4",
        "Labels": {
            "description": "Eclipse Mosquitto MQTT Broker",
            "maintainer": "Roger Light <roger@atchoo.org>"
        },
        "Mounts": [
            {
                "Destination": "/mosquitto/config",
                "Mode": "rw",
                "Propagation": "rprivate",
                "RW": true,
                "Source": "/volume1/docker/mosquitto/config",
                "Type": "bind"
            },
            {
                "Destination": "/mosquitto/data",
                "Mode": "rw",
                "Propagation": "rprivate",
                "RW": true,
                "Source": "/volume1/docker/mosquitto/data",
                "Type": "bind"
            },
            {
                "Destination": "/mosquitto/log",
                "Mode": "rw",
                "Propagation": "rprivate",
                "RW": true,
                "Source": "/volume1/docker/mosquitto/log",
                "Type": "bind"
            }
        ],
        "Names": [
            "/eclipse-mosquitto"
        ],
        "NetworkSettings": {
            "Networks": {
                "domotique": {
                    "Aliases": null,
                    "DriverOpts": null,
                    "EndpointID": "5d6ab70905b9ed880438ca8ba602ad1c248026d5d3c62ff8838ca928078b0962",
                    "Gateway": "172.19.0.1",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "IPAMConfig": null,
                    "IPAddress": "172.19.0.3",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "Links": null,
                    "MacAddress": "02:42:ac:13:00:03",
                    "NetworkID": "dc489bbc3f634dbc781c4feeac4d1e27607bfa46b19cd05e1c07430feec99a2a"
                }
            }
        },
        "Ports": [
            {
                "IP": "0.0.0.0",
                "PrivatePort": 1883,
                "PublicPort": 1883,
                "Type": "tcp"
            },
            {
                "IP": "0.0.0.0",
                "PrivatePort": 9001,
                "PublicPort": 9001,
                "Type": "tcp"
            }
        ],
        "StartedAt": 1710838375,
        "State": "running",
        "Status": "Up 2 days"
    }
]
saisissez ou collez du code ici

voici le json que j’essaie de Parser mais je n’y arrive pas :frowning:

Mon objectif est de recupérer les attributs : - State
- Status
- Created
- Id
pour un item avec le Name = « /zoffline-zoffline »

j’ai donc écris ce sensor :

  - platform: rest
     name: Container Zoffline
     icon: "mdi:docker"
     headers:
       x-api-key: "ptr_rEgEuajyqUuN+fVuDtajCH8FM+ph2rIiP/9jEHAY6hs="
     verify_ssl: false
     json_attributes_path: "$.[0]"
     json_attributes:
       - State
       - Status
       - Created
       - Id
     value_template: "{{ value_json[0].State }}" #"{{ value_json['Created'] | as_datetime | as_local }}"
     params:
       all: true
       filters: '{"Names":["/zoffline-zoffline"]}'
     resource: https://192.168.1.30:9443/api/endpoints/2/docker/containers/json

Mais il me retourne un erreur dans les journaux :confused:
Template variable error: dict object has no element 0 when rendering '{{ value_json[0].State }}'

Tu sors ça d’où ? :thinking:
Quand je lis la doc, j’ai l’impression que ç’est pour la requête, et non pour filtrer la réponse.
image

Git

Essaie ça :

- platform: rest
     name: Container Zoffline
     icon: "mdi:docker"
     headers:
       x-api-key: "ptr_rEgEuajyqUuN+fVuDtajCH8FM+ph2rIiP/9jEHAY6hs="
     verify_ssl: false
     json_attributes_path: "$.[0]"
     json_attributes:
       - State
       - Status
       - Created
       - Id
     value_template: "{{ value_json[0].State }}" #"{{ value_json['Created'] | as_datetime | as_local }}"
     resource: https://192.168.1.30:9443/api/endpoints/2/docker/containers/json

Si ça te retourne le premier élément, le problème vient du filtre.
Et je parierais sur le caractère slash /. Je pense qu’il faut l’encoder. Tu peux essayer de le remplacer par %2F.

Oui ça retourne bien les infos du 1er noeud.

Pour contourner le pb du /, je suis passé par l’Id du container. mais j’ai le même soucis :frowning:

Template variable error: dict object has no element 0 when rendering '{{ value_json[0].State }}'

essaie ça :

- platform: rest
     name: Container Zoffline
     icon: "mdi:docker"
     headers:
       x-api-key: "ptr_rEgEuajyqUuN+fVuDtajCH8FM+ph2rIiP/9jEHAY6hs="
     verify_ssl: false
     json_attributes_path: "$.[0]"
     json_attributes:
       - State
       - Status
       - Created
       - Id
     value_template: "{{ value_json[0].State }}" #"{{ value_json['Created'] | as_datetime | as_local }}"
     params:
       all: true
       filters: '{"Names=/zoffline-zoffline"}'
     resource: https://192.168.1.30:9443/api/endpoints/2/docker/containers/json

Pas mieux :frowning:

On pourrait pas contourner le problème via le template ?

J’ai contourné le problème :wink: En allant directement dans l’API du conteneur !

sensor:
 - platform: rest
    name: Container Zoffline
    icon: "mdi:docker"
    headers:
      x-api-key: "ptr_rEgEuajyqUuN+fVuDtajCH8FM+ph2rIiP/9jEHAY6hs="
    verify_ssl: false
    scan_interval: 5
    value_template: "{{ value_json.State.Running }}"
    resource: https://192.168.1.30:9443/api/endpoints/2/docker/containers/259b7beafaa4066ec8537f7029e8bf1b034fd9388ff9821ebbe5d7d0c3ab52df/json

Maintenant que j’ai un rest senor qui fonctionne et des rest commande qui fonctionnent :

rest_command:
  zoffline_start_container:
    url: "https://192.168.1.30:9443/api/endpoints/2/docker/containers/259b7beafaa4066ec8537f7029e8bf1b034fd9388ff9821ebbe5d7d0c3ab52df/start"
    method: POST
    timeout: 30
    headers:
      X-API-Key: "ptr_rEgEuajyqUuN+fVuDtajCH8FM+ph2rIiP/9jEHAY6hs="
    verify_ssl: false
    payload: "{}"
  zoffline_stop_container:
    url: "https://192.168.1.30:9443/api/endpoints/2/docker/containers/259b7beafaa4066ec8537f7029e8bf1b034fd9388ff9821ebbe5d7d0c3ab52df/stop"
    method: POST
    timeout: 30
    headers:
      X-API-Key: "ptr_rEgEuajyqUuN+fVuDtajCH8FM+ph2rIiP/9jEHAY6hs="
    verify_ssl: false
    payload: "{}"

J’aimerai bien que les 3 soient liés par un switch. Vous pensez que cela est possible ?

2 « J'aime »

C’est la partie la plus facile! :grin:
Regarde ici : Template Switch - Home Assistant