Use this static method to discover all available magic home lights on your network:
var lights = await Light.DiscoverAsync();
This will take approximately 1 second.
If you have many leds you might need more time to discover all of them, therefore you'll have to use the LightDiscovery class and set a custom timeout.
LightDiscovery.Timeout = 2000;
var lights = await LightDiscovery.Discover();
Light.DiscoverAsync()
and LightDiscovery.DiscoverAsync()
are doing the same thing.
The light entity contains almost all logic of the library.
- Initialize your light with its local ip address:
var light = new Light("192.168.1.1");
- Connect to it:
await light.ConnectAsync();
- You're now ready to use it.
These are the methods used to interact with the light.
Use this to turn it on or off:
await light.TurnOnAsync(); //or light.SetPowerAsync(true)
await light.TurnOffAsync(); //or light.SetPowerAsync(false)
await light.SetColorAsync(0, 127, 243);
Or use the Color class:
await light.SetColorAsync(Colors.Purple);
Set cold white:
await light.SetColdWhiteAsync(255); //or light.SetColorAsync(255, 255, 255)
If you have a bulb or strip that supports warm white, use:
await light.SetWarmWhiteAsync(255);
The light has some factory patterns:
await light.SetPresetPatternAsync(PresetPattern.PurpleGradualChange, 50);
Make your own patterns by using this:
var colors = new List<Color>()
{
new Color(255, 0, 0), //Red
new Color(0, 255, 0), //Green
Colors.Green //Or just use Colors class
};
await light.SetCustomPatternAsync(colors, TransitionType.Gradual, 50);
The light's properties are populated whenever you use any method, but sometimes the light might fail so it's recommended to use this from time to time to send a request to the light and get it's status (Light mode, Color, Brightness, etc.):
await light.RefreshAsync();
Print your light's status:
Console.WriteLine(light.ToString());
Color class for library.
Make a new color:
var color = new Color(25, 12, 164);
Or use a pre-set:
var color = Colors.Purple;
Empty / Transparent / Black:
var color = Colors.Empty; // new Color();