Create a HomeyScript script
homey_script_createCreate a new Homey script and get its ID. Write reusable JavaScript that runs on the hub, takes arguments, and returns values to Flows.
Instructions
Creates a new script and returns the id the Homey assigned to it. Use that id afterwards: the name is not an address, and two scripts may share one. The script runs on the Homey, so it has the Homey API available as Homey, writes output with log(), and can hand a value back to the Flow that started it with return or tag(). Write scripts to be reusable. Take what varies as an argument rather than baking it in: the HomeyScript Flow card passes text into the script as args[0], so one script can serve several Flows and several rooms. Prefer looking a device up by what it IS over what its id is, for example by zone and capability, so the script survives a device being replaced. Prefer returning a value and letting the Flow act on it over acting inside the script. A script that answers "should I open the window" can be reused; one that also opens the window cannot. A hard-coded device id is acceptable when there is genuinely no other way, or when a lookup would be more fragile than the id. It is the exception, and it is worth a comment saying why. This server cannot see log() output: it goes to the HomeyScript app console and no route here reads it. What comes back is the return value, so return whatever needs checking rather than logging it. While a script is being written, return an object with the intermediate values in it; trim it to the real answer once it works. Run it with homey_script_run once created, because a script that has never run is a script nobody has checked.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The JavaScript to run on the Homey. | |
| name | Yes | A short descriptive name, shown in the HomeyScript app and when picking the script in a Flow. |