Coder Social home page Coder Social logo

stoman / milightapi Goto Github PK

View Code? Open in Web Editor NEW
28.0 8.0 8.0 149 KB

A java API for MiLight light bulbs. Other brands of light bulbs are also compatible, for instance EasyBulb, LimitlessLED, etc.

Home Page: https://stoman.github.io/MilightAPI/de/toman/milight/package-summary.html

License: MIT License

Java 99.92% Makefile 0.08%
milight-light-bulbs java-api java easybulb limitlessled milight milight-controller milight-lamp milight-bulbs

milightapi's Introduction

MiLight API

This is an API for MiLight light bulbs written in Java. Other brands of light bulbs are also compatible, for instance EasyBulb, LimitlessLED, etc. With this API it is easy to switch lights on and off, change color and brightness and other settings. Additionally, tools like an ambient light effect, fading animations and music visualizations are included. Only a WiFi box and some light bulbs are needed to run this API.

Pull requests as well as notifications about usages of this API are always appreciated. Documentation of all classes is available at GitHub Pages.

Basic Usage

Connect your WiFi box to the lights as described in the manual. Find the local IP address of your box in the local network. This information can be found at the interface of your router, for instance. Now you can run the API on a machine connected to the same network.

To connect to your WiFi box create a WiFiBox object in your Java application:

String ip = "192.168.1.42"; //add your custom IP here
WiFiBox box = new WiFiBox(ip);

Additional constructors with custom ports or other types of addresses are also available. Individual groups of lights can be created like this:

Lights groupA = box.getLights(1);
Lights groupB = new Lights(ip, 2);

All commands available on a remote control or an app connected to this box are now available, for example:

//switch all lights on
box.on();
//switch group 4 of
box.off(4);
//switch group 2 to disco mode
box.discoMode(2);
//make the disco mode faster
box.discoModeFaster(2);
//switch the color of group 3 to blue
box.color(3, new MilightColor(Color.BLUE));
//dim group 1
box.brightness(1, MilightColor.MIN_BRIGHTNESS);

Many more commands are available, check the docs to read more. To display colors the lights change their brightness and hue as well switch between white and color mode to resemble the chosen color as close as possible.

Ambient Light and Music Visualizer

Lights can be used to create an ambient light effect. This means the lights will resemble the colors of the screen of your PC. Use this to lighten your room fitting to a movie you are watching or similar. AmbientLight can be used like this:

AmbientLight ambient = new AmbientLight(groupA);//or some other Lights object
ambient.start();

The effect can be stopped with

ambient.stop();

More configuration is available and described in the documentation.

Similarly, a visualization of the music played on your machine can be created. The source to read the music from needs to be available as a TargetDataLine. The function MusicVisualizer.getDefaultLine() is available to find the most common data lines. The visualizer can be started like this using the default line:

MusicVisualizer vis = new MusicVisualizer(groupB);
vis.start();

The effect can be stopped with

vis.stop();

Timer

There is a timer available to fade from one color or brightness to another or switch the lights off after a certain amount of time. Timers can be used like this:

Timer timer = new Timer(
	groupA, //the lights to control,
	10000, //animation time in milliseconds
	new MilightColor(Color.BLUE), //start color or brightness
	new MilightColor(Color.BLACK), //target color or brightness
	true //switch the lights off after the animation	
);
timer.start();

Watching Events

All commands sent out by the API are available as events to make it possible to react to commands sent out. Add a LightListener like this:

groupA.addLightListener(new LightListener() {
	public void lightsChanged(LightEvent e) {
		//work with the event
	}
});

The following events are available:

Similarly, there is a TimerListener available to catch the event that the timer has finished its animation.

There is no way to read the current state of a light from the WiFi box. However, we can track all commands sent by the API to compute the current state. To automatically track the state of a light use the LightState class. Note, that changes made by another remote control or app are not noticed by this class.

Author

This library is written by Stefan Toman and available under the MIT license.

milightapi's People

Contributors

stoman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

milightapi's Issues

More explaination

Hello.

I have tried to use your api as you have explained in your README but failed.

I have a iBox2 of mi-light as a wifi box connected to my network.
I have created a WifiBox with the ip of my iBox2.
When I try to do box.on() or any other command nothing happen.
I don’t have any error but no light turns ooh.

Can you explain me exactly how to install and use your api?

thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.