How to connect to Homey Pro via Web API and Control Devices?

Hello Homey Community!

I’m working on a project where I need to connect to a Homey Pro device using the Homey Web API. My goal is to have a website that authenticates a user and retrieve all their devices, then be able to control the devices individually (such as turning lights on/off, adjusting thermostat settings, etc.).

Can someone provide a code snippet or guide me on the following:

  1. How to authenticate a user with OAuth2 and obtain an access token.
  2. How to use the Homey Web API to retrieve all devices associated with the user’s Homey system.
  3. How to send commands to control individual devices (e.g., toggling on/off for lights or setting a new temperature for thermostats).

It would be great if you could provide an example using Node.js (or any other language) that interacts with Homey Pro through the Web API.

Thanks in advance for your help!

Also, whenever i use this snippet from their docs, it seems Homey doesn’t have any property called devices. Can anyone guide me a bit better?

const devices = await Homey.devices.getDevices();

Check the source of homeydash.com for instance.