Skip to main content

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.

PackageFunctionReturnsParameterExample
generalprint(message)voidmessage'Hello Earth'
error(message)voidmessage'No object found'
sleep(seconds)voidseconds5
statestate.get(topic)statetopic'asset.hvac.bosch.temperature'
state.set(topic, value)voidtopic'weather.eindhoven.pressure'
voidvalue1013
httphttp.get(url)bodyurlhttps://google.com
http.post(url, data[, options])bodyurlhttps://app.mydomain.com/login
bodydata{"username": "bob"}
bodyoptions{"headers": ["Content-Type", "application/json"]}
http.request(options)responseoptions{url: "https://app.mydomain.com/login"}
responseoptions{"headers": ["Content-Type", "application/json"]}
responseoptions{maxRedirects: 0} }
mqttmqtt.get(topic)texttopic'/building_a/room_b/temperature'
mqtt.publish(topic, message [, options])texttopic'/building_a/room_b/temperature'
textmessage{"temperature", 12}
textoptions{qos: 1}
textoptions{retain: true}