Namespace: global

All properties & methods in this namespace are accessible in a HomeyScript.

Example

// Get all devices
const devices = await Homey.devices.getDevices();

// Loop over all devices
for (const device of Object.values(devices)) {

  // If this device is a light (class)
  // Or this is a 'What's plugged in?'-light (virtualClass)
  if (device.class === 'light' || device.virtualClass === 'light') {
    log(`\nTurning '${device.name}' on...`);

    // Turn the light on by setting the capability `onoff` to `true`
    await device.setCapabilityValue('onoff', true)
      .then(() => log('OK'))
      .catch(error => log(`Error:`, error));
  }
}

Properties

_

(static) _: Object

Shortcut to lodash.

Type

  • Object

__filename__

(static) __filename__: String

The filename of the HomeyScript.

Type

  • String

__last_executed__

(static) __last_executed__: Date

When the HomeyScript has last executed.

Type

  • Date

__ms_since_last_executed__

(static) __ms_since_last_executed__: Number

Milliseconds since the HomeyScript has last executed.

Type

  • Number

__script_id__

(static) __script_id__: String

The Script ID of the HomeyScript.

Type

  • String

args

(static) args: Array

Provided arguments to this script.

Type

  • Array

Example

log(args[0]); // "myArgument"

Buffer

(static) Buffer: Object

Shortcut to Buffer.

Type

  • Object

Homey

(static) Homey: HomeyAPI

A HomeyAPI instance.

Type

  • HomeyAPI

Example

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

http

(static) http: Object

Shortcut to http.

Type

  • Object

https

(static) https: Object

Shortcut to https.

Type

  • Object

URLSearchParams

(static) URLSearchParams: Class

Shortcut to URLSearchParams.

Type

  • Class

Methods

fetch

(async, static) fetch(url, options)

Shortcut to node-fetch.

Parameters

Name Type Description
url
String
options
Object

get

(static) get(key)

Get a global value that's accessible between HomeyScripts.

Parameters

Name Type Description
key
String

Key of the property

keys

(static) keys(): Array

Gets all keys of global values.

Returns

Array

log

(async, static) log(…arg1)

Log to the console.

Parameters

Name Type Description
arg1
Mixed <repeatable>

Example

log('Hello World!');

say

(async, static) say(text)

Says something over the internal speaker.

Parameters

Name Type Description
text
String

Example

await say('Hello world!');

set

(static) set(key, value)

Set a global value that's accessible between HomeyScripts.

Parameters

Name Type Description
key
String

Key of the property

value
Mixed

Value of the property

tag

(async, static) tag(id, value)

Creates or updates a Flow Tag. These are persistent across reboots.

Delete a Flow Tag by providing null as value.

Parameters

Name Type Description
id
String

ID of the Tag

value
String | Number | Boolean | null

Value of the Tag

Example

await tag('My Tag', 1337); // Create
await tag('My Tag', 1338); // Update
await tag('My Tag', null); // Delete

wait

(async, static) wait(milliseconds)

Resolves after milliseconds milliseconds.

Parameters

Name Type Description
milliseconds
Number

Example

log('Foo');
await wait(1000);
log('Bar');