JavaScript
All standard JavaScript functions and ECMAScript language constructs are supported. The scripts are executed in a sandbox Virtual Machine and do not have access to the operating system or Node.js packages. The following packages are supported. All values are returned as promises and can be obtained using the await
statement. When the functions are used in importers the await
is automatically included.
Package | Function | Returns | Parameter | Example |
---|---|---|---|---|
general | print(message) | void | message | 'Hello Earth' |
error(message) | void | message | 'No object found' | |
sleep(seconds) | void | seconds | 5 | |
state | state.get(topic) | state | topic | 'asset.hvac.bosch.temperature' |
state.set(topic, value) | void | topic | 'weather.eindhoven.pressure' | |
void | value | 1013 | ||
http | http.get(url) | body | url | https://google.com |
http.post(url, data[, options]) | body | url | https://app.mydomain.com/login | |
body | data | {"username": "bob"} | ||
body | options | {"headers": ["Content-Type", "application/json"]} | ||
http.request(options) | response | options | {url: "https://app.mydomain.com/login"} | |
response | options | {"headers": ["Content-Type", "application/json"]} | ||
response | options | {maxRedirects: 0} } | ||
mqtt | mqtt.get(topic) | text | topic | '/building_a/room_b/temperature' |
mqtt.publish(topic, message [, options]) | text | topic | '/building_a/room_b/temperature' | |
text | message | {"temperature", 12} | ||
text | options | {qos: 1} | ||
text | options | {retain: true} |