ebaauw / homebridge-hue

Homebridge plugin for Philips Hue
Apache License 2.0
898 stars 91 forks source link

Support for toggling v2 API behaviors like v1 schedules #1087

Closed nano9g closed 2 years ago

nano9g commented 2 years ago

Issue

After the v2 Hue API became available, I happened to delete and recreate all my Wake Up bridge automations through the Hue app. This had the unfortunate effect of moving them from the v1 schedules API to the v2 behaviors API, so they're no longer made available to HomeKit when I set schedules=true for Homebridge Hue. (Unlike in #1028, I'm not using Hue Labs, so the CLIPGenericStatus sensor solution doesn't apply.)

I know that the long term plan is to create a new version of Homebridge Hue for the v2 API, but I was wondering if it would be feasible to get support for toggling behaviors sooner.

I've provided API responses from my bridge for both schedules and behaviors below and, as you can see, schedules returns nothing. In terms of toggling behaviors, the enabled boolean field is used, unlike the string status from v1.

Please let me know if you need any more information or if I can help in any way. Thanks very much!

GET https://<bridge>/api/<user>/schedules

Response:
{}

GET https://<bridge>/clip/v2/resource/behavior_instance

Header Value
hue-application-key <user>
Response (edited down a bit as it's pretty long):
{
  "errors": [],
  "data": [
    {
      "configuration": {
        "fade_in_duration": { "seconds": 1200 },
        "when": {
          "recurrence_days": ["saturday", "sunday"],
          "time_point": { "time": { "hour": 6, "minute": 0 }, "type": "time" }
        },
        "where": [
          {
            "group": {
              "rid": "<id>",
              "rtype": "room"
            },
            "items": [
              {
                "rid": "<id>",
                "rtype": "light"
              }
            ]
          },
          {
            "group": {
              "rid": "<id>",
              "rtype": "room"
            },
            "items": [
              {
                "rid": "<id>",
                "rtype": "light"
              }
            ]
          }
        ]
      },
      "dependees": [
        {
          "level": "critical",
          "target": {
            "rid": "<id>",
            "rtype": "room"
          },
          "type": "ResourceDependee"
        },
        {
          "level": "critical",
          "target": {
            "rid": "<id>",
            "rtype": "light"
          },
          "type": "ResourceDependee"
        },
        {
          "level": "critical",
          "target": {
            "rid": "<id>",
            "rtype": "room"
          },
          "type": "ResourceDependee"
        },
        {
          "level": "critical",
          "target": {
            "rid": "<id>",
            "rtype": "light"
          },
          "type": "ResourceDependee"
        }
      ],
      "enabled": true,
      "id": "<id>",
      "last_error": "",
      "metadata": { "name": "Wake Weekends" },
      "migrated_from": "/resourcelinks/<id>",
      "script_id": "<id>",
      "status": "running",
      "type": "behavior_instance"
    },
    {
      "configuration": {
        "fade_in_duration": { "seconds": 600 },
        "when": {
          "recurrence_days": [
            "monday",
            "tuesday",
            "wednesday",
            "thursday",
            "friday"
          ],
          "time_point": { "time": { "hour": 6, "minute": 0 }, "type": "time" }
        },
        "where": [
          {
            "group": {
              "rid": "<id>",
              "rtype": "room"
            },
            "items": [
              {
                "rid": "<id>",
                "rtype": "light"
              }
            ]
          },
          {
            "group": {
              "rid": "<id>",
              "rtype": "room"
            },
            "items": [
              {
                "rid": "<id>",
                "rtype": "light"
              }
            ]
          }
        ]
      },
      "dependees": [
        {
          "level": "critical",
          "target": {
            "rid": "<id>",
            "rtype": "room"
          },
          "type": "ResourceDependee"
        },
        {
          "level": "critical",
          "target": {
            "rid": "<id>",
            "rtype": "light"
          },
          "type": "ResourceDependee"
        },
        {
          "level": "critical",
          "target": {
            "rid": "<id>",
            "rtype": "room"
          },
          "type": "ResourceDependee"
        },
        {
          "level": "critical",
          "target": {
            "rid": "<id>",
            "rtype": "light"
          },
          "type": "ResourceDependee"
        }
      ],
      "enabled": true,
      "id": "<id>",
      "last_error": "",
      "metadata": { "name": "Wake Weekdays" },
      "migrated_from": "/resourcelinks/<id>",
      "script_id": "<id>",
      "status": "running",
      "type": "behavior_instance"
    },
    {
      "configuration": {
        "what": [
          {
            "group": {
              "rid": "<id>",
              "rtype": "room"
            },
            "recall": {
              "rid": "<id>",
              "rtype": "recipe"
            }
          }
        ],
        "when_extended": {
          "recurrence_days": [
            "sunday",
            "monday",
            "tuesday",
            "wednesday",
            "thursday",
            "friday",
            "saturday"
          ],
          "start_at": {
            "time_point": {
              "time": { "hour": 7, "minute": 11 },
              "type": "time"
            }
          }
        },
        "where": [
          {
            "group": {
              "rid": "<id>",
              "rtype": "room"
            }
          }
        ]
      },
      "dependees": [],
      "enabled": false,
      "id": "<id>",
      "last_error": "",
      "metadata": { "name": "Test" },
      "script_id": "<id>",
      "status": "initializing",
      "type": "behavior_instance"
    }
  ]
}
ebaauw commented 2 years ago

I'm sorry, I won't be implementing any Hue API v2 features in Homebridge Hue (other than the already implemented event stream).

You can still create schedules using the v1 API, just not with the Hue app, apparently. And the Hue app for the gen-1 bridge crashes when trying to connect to a gen-2 bridge.

nano9g commented 2 years ago

I totally understand. Thanks for the quick response!