Replace the code of a HomeyScript script
homey_script_updateReplace an existing Homey script's code by id or exact name, and get the previous code back to undo changes if needed.
Instructions
Replaces the code of a script that already exists, found by id or exact name. The previous code is returned so the change can be undone from the result alone. 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.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The JavaScript that replaces what is there now. | |
| script | Yes | The script id, or its exact name. |