REST API docs for automations?

Hi, friends.

I’ve been able to reverse engineer a little bit of this by reading the frontend code: https://github.com/home-assistant/frontend/blob/fafad302ba5dd8b279ace7eb082a2bb4046c670f/src/panels/config/automation/ha-config-automation.ts

The frontend gets a list of automations by parsing the list of States. You can get the states with the websocket message get_state and finding any states in the automation domain. This gives back some basic information abotu the automations, e.g.:

$ ghastly state list | jq 'map(select(.entity_id | startswith("automation.")).attributes)'
[
  {
    "friendly_name": "Upstairs Heater - Off",
    "id": "5fd2063e021b476b800d42790ae33572",
    "last_triggered": "2020-05-04T03:45:00.024172+00:00"
  },
  {
    "friendly_name": "Growlights On at 6am",
    "id": "4956d98ce52246b395295e76440bd979",
    "last_triggered": "2020-05-19T13:00:00.059517+00:00"
  },
  {
    "friendly_name": "Downstairs Heater - Off",
    "id": "211bc95e4741423b9a52058da6747298",
    "last_triggered": "2020-05-14T18:01:00.056826+00:00"
  },
  {
    "friendly_name": "Downstairs Heater - On",
    "id": "f869704cfd1f497891b4bfed86da3ce7",
    "last_triggered": "2020-05-13T13:29:09.061536+00:00"
  },
  {
    "friendly_name": "Upstairs Heater - On",
    "id": "625933858a54497390306f643e59b4ef",
    "last_triggered": "2020-05-03T20:29:10.850650+00:00"
  },
  {
    "friendly_name": "Bedroom lights at dawn",
    "id": "22650126ff7c46059363912643842fd6",
    "last_triggered": "2020-05-13T13:15:00.055598+00:00"
  },
  {
    "friendly_name": "Growlights Off at 6pm",
    "id": "73b6047662104b3da06bf75fd58b0c8f",
    "last_triggered": "2020-05-19T01:00:00.038803+00:00"
  }
]

Given the id from attributes, the REST URL config/automation/config/[automation-id] can be used to retrieve the details of an automation:

$ ghastly raw config/automation/config/22650126ff7c46059363912643842fd6 | jq
{
  "action": {
    "data": {
      "brightness": 255,
      "entity_id": "light.ge_14294_inwall_smart_dimmer_level",
      "transition": 900
    },
    "service": "light.turn_on"
  },
  "alias": "Bedroom lights at dawn",
  "condition": {
    "condition": "or",
    "conditions": [
      {
        "condition": "state",
        "entity_id": "device_tracker.oneplus7t_2",
        "state": "home"
      },
      {
        "condition": "state",
        "entity_id": "device_tracker.oneplus6tsingle_2",
        "state": "home"
      }
    ]
  },
  "id": "22650126ff7c46059363912643842fd6",
  "trigger": [
    {
      "at": "06:15:00",
      "platform": "time"
    }
  ]
}

This is RESTful, so you can configure an automation by POSTing the same sort of JSON blob back to the same URL config/automation/config/[automation-id].

Similarly, deleting an automation is a RESTful DELETE to that same API.

2 Likes