-
Notifications
You must be signed in to change notification settings - Fork 47
Turn light on off
Markus edited this page Jul 5, 2019
·
1 revision
Here is an example to turn a light on or off and set brightness level
// Initialize COM Port
ZigBeeSerialPort zigbeePort = new ZigBeeSerialPort("COM4");
// Initialize dongle hardware e.g. CC2531
IZigBeeTransportTransmit dongle = new ZigBeeDongleTiCc2531(zigbeePort);
// Initialize NetworkManager
ZigBeeNetworkManager networkManager = new ZigBeeNetworkManager(dongle);
// Send OnCommand
await networkManager.Send(endpointAddress, new OnCommand());
// Get node by it's network address
var node = networkManager.GetNode(4711);
// Create a endpoint address object
ZigBeeEndpointAddress endpointAddress = null;
// Get default endpoint
var endpoint = node.Endpoints.Values.FirstOrDefault();
if (endpoint != null)
{
// Get endpoint address
endpointAddress = endpoint.GetEndpointAddress();
}
else
{
throw new Exception("No Endpoint found!");
}
// Send OffCommand
await networkManager.Send(endpointAddress, new OffCommand());
// Send MoveToLevelCommand for setting brightness
var command = new MoveToLevelWithOnOffCommand()
{
// Level from 0 to 255, where 255 = 100 %
Level = byte.Parse(level),
// Time for changing (smoothly overflow)
TransitionTime = ushort.Parse(time)
};
await networkManager.Send(endpointAddress, command);