@picomitchell See the following.
At the top of your file, put matter = require('matter');
.
Turning on and off:
matter.sendCommand("5716184942583194821", 1, "On/Off", "On", {}, (error, response) => console.log(JSON.stringify(error) + ", " + JSON.stringify(response))); // Turn on
matter.sendCommand("5716184942583194821", 1, "On/Off", "Off", {}, (error, response) => console.log(JSON.stringify(error) + ", " + JSON.stringify(response))); // Turn off
matter.sendCommand("5716184942583194821", 1, "On/Off", "Toggle", {}, (error, response) => console.log(JSON.stringify(error) + ", " + JSON.stringify(response))); // Toggle
The above assumes the node id of the device you are controlling is 5716184942583194821 (which you get from the getNodes()
function) and the On/Off cluster you want to control is located at endpoint 1. Most devices have all the relevant clusters positioned at endpoint 1, but if one device has several logical parts (like a lamp with multiple light sources), they would typically have one endpoint per light source. Also Matter bridges have many endpoints; each bridged device is exposed as one or multiple endpoints.
The third parameter "On/Off" is the name of the cluster and the following parameter is the name of the command (contained within that cluster) that you want to execute. These three commands take no option fields in this case, so the fourth parameter is just an empty object {}
. The last parameter is a callback, executed when the the remote device has delivered the response, possibly with some return fields.
Setting brightness:
matter.sendCommand("5716184942583194821", 1, "Level Control", "MoveToLevel", {"Level": 110, "TransitionTime": 0, "OptionsMask": 1, "OptionsOverride": 1}, (error, response) => console.log(JSON.stringify(error) + ", " + JSON.stringify(response)));
The level you can set is typically in the range 1 (minimum) to 254 (maximum). Set OptionsOverride
to 0 if you don't want the command to take effect in case the light is off (so that when you later turn it on, it would be at the same level it was before). You can also replace the command name to MoveToLevelWithOnOff to make sure the light turns on when you simply set brightness to something more than 1, in case it was off. The transition time is in the unit 10ths of a second.
Setting color using hue/saturation:
matter.sendCommand("5716184942583194821", 1, "Color Control", "MoveToHueAndSaturation", {"Hue": 254, "Saturation": 254, "TransitionTime": 0, "OptionsMask": 1, "OptionsOverride": 1}, (error, response) => console.log(JSON.stringify(error) + ", " + JSON.stringify(response)));
Hue and Saturation fields are both from 0 to 254.
Setting color temperature:
matter.sendCommand("5716184942583194821", 1, "Color Control", "MoveToColorTemperature", {"ColorTemperatureMireds": 370, "TransitionTime": 0, "OptionsMask": 1, "OptionsOverride": 1}, (error, response) => console.log(JSON.stringify(error) + ", " + JSON.stringify(response)));
The color temperature is in "mireds" (https://en.wikipedia.org/wiki/Mired). The Tapo light bulb has a range from 153 (coldest) to 400 mireds (warmest).
You can use the "command" window in the hub sdk to experiment with various commands. I recommend you to also use the Matter Other action in the app to experiment with various options.
To monitor the state, you can use the subscription feature:
let subscription = matter.subscribe("5716184942583194821", [{endpointId: 1}]);
If you want to filter on a specific endpoint/cluster/attribute, you declare that in the options parameter (all those three are optional). It is an array so you can put multiple filter (the updated attribute must match at least one filter). For example, [{endpointId: 1, clusterName: "Level Control", attributeName: "CurrentLevel"}]
will only match the brightness. For On/Off status, you would want [{endpointId: 1, clusterName: "On/Off", attributeName: "OnOff"}]
. The filter [{}]
will listen to everything (wildcard).
You get updates by registering an event listener for the update
event:
subscription.on("update", function(d) {
console.log("connected: " + d.connected);
if (d.updates === undefined) return;
console.log(JSON.stringify(d.updates));
});
Initially you will get an immediately delivered event containing the current status (assuming the device is connected). This is indicated by d.initialProbe == true
. You will get an update every time the connectivity changes true/false. The attribute updates will contain something like {"1":{"Level Control":{"CurrentLevel":254}}}
where from out to in you have endpoint number, cluster name, attribute name, value. Multiple attributes will be reported at once if they are updated at the same time. To see the whole structure of a Matter device, I recommend you to set up a subscription for the wildcard filter and print the initial probe result to the console.
You can call the cancel()
method on the subscription to stop getting updates (which also releases the resources).