Giter Site home page Giter Site logo

yeedart's Introduction

Yeedart

Pub Build Status

Dart library for controlling Yeelight products over LAN.

More info about Yeelight API:

Contents

Installation

  1. Depend on it

Run this command:

With dart:

$ dart pub add yeedart

With flutter:

$ flutter pub add yeedart

This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get/flutter pub get):

dependencies:
  yeedart: ^0.3.2
  1. Import it

Now in your Dart code, you can use:

import 'package:yeedart/yeedart.dart';

Usage

Device discovery

First of all, you need to know your device's IP address and port. You can use Yeelight.discover() method which returns list of DiscoveryResponse.

final responses = await Yeelight.discover();
final response = responses.first; // or filter..

Each response contains IP address and port for given device and other properties (name, firmware version, current state,...).

ℹ️ You can also specify timeout for discovery. Default is 2 seconds.

Note that for device discovery to properly work on Android, you at least need the INTERNET permission granted.

Connect to the device

final device = Device(
  address: InternetAddress("192.168.1.183"),
  port: 55443,
);

await device.turnOn(); // turn the device on

// set red color with smooth transition
await device.setRGB(
  color: Colors.red,
  effect: const Effect.smooth(),
  duration: const Duration(milliseconds: 500),
);

await device.setBrightness(brightness: 70); // set brightness to 70 %

device.disconnect(); // always disconnect when you are done!

⚠️ When you send a Command, new TCP connection will be created automatically. This single TCP connection is then used for another command(s). But when you are done, you should close the connection.

ℹ️ Note that when you call device.disconnect() and then call for example device.turnOff(), new TCP connection will be created automatically.

ℹ️ If you don't want to send any command and just listen on the notificationMessageStream, use the device.connect() to create a connection manually.

ℹ️ Also note that Yeelight connections are rate-limited to 60 per minute.

Main and background light

Some devices can be equiped with two lights: main and background. Methods in Device class control main light by default (for example device.setRGB(color: Colors.red) sets RGB color for main light. If you want to set RGB color for background light, you have to specify lightType parameter: device.setRGB(color: Colors.red, lightType: LightType.backgroud);.

You can also use LightType.both but ONLY for toggling: device.toggle(lightType: LightType.both).

Flow

Flow (color flow) is basically a list of transitions. To start a flow use startFlow() method and provide Flow. Flow has 3 required parameters:

  • count - number of transitions to run, 0 for infinite loop. If you have 10 transitions and count is 5, it will run only first 5 transitions!
  • action - specifies action to take after the flow ends.
    • FlowAction.stay to stay at the last state when the flow is stopped.
    • FlowAction.recover to recover the state before the flow.
    • FlowAction.turnOff to turn off.
  • transitions - list of FlowTransition, FlowTransition.rgb(), FlowTransition.colorTemperature() or FlowTransition.sleep().

Following example will loop red, green and blue colors at full brightness.

await device.startFlow(
  flow: const Flow(
    count: 0,
    action: FlowAction.recover(),
    transitions: [
      FlowTransition.rgb(color: 0xff0000, brightness: 100),
      FlowTransition.sleep(duration: Duration(milliseconds: 500)),
      FlowTransition.rgb(color: 0x00ff00, brightness: 100),
      FlowTransition.sleep(duration: Duration(milliseconds: 500)),
      FlowTransition.rgb(color: 0x0000ff, brightness: 100),
      FlowTransition.sleep(duration: Duration(milliseconds: 500)),
    ],
  ),
);

To manually stop flow, use device.stopFlow().

This library also includes some predefined flows:

  • Flow.rgb() - changes color from red, to green to blue
  • Flow.police - changes red and blue color like police lights.
  • Flow.pulse() - creates pulse with given color

Scene

Scene allows you to set light to specific state. To use scene, use setScene() method and provide Scene.

You can use:

  • Scene.color() or Scene.hsv() to set color and brightness
  • Scene.colorTemperature to set color temperature and brightness
  • Scene.colorFlow() to start a color Flow
  • Scene.autoDelayOff() to turn on the device to specified brightness and start a timer to turn off the light after specified number of minutes.

Example:

device.setScene(scene: Scene.color(color: 0xff0000, brightness: 100));

Features and bugs

Please file feature requests and bugs at the issue tracker.

yeedart's People

Contributors

fmichenaud avatar guyluz11 avatar janstol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

yeedart's Issues

Name is empty

The device from Yeelight.discover() return with an empty name '' although the name appears in the Yeelight app.

Device type: yeelight 1SE

Other params seem correct.

NotificationMessageStream not sending new events

Hello,

I am trying to listen to state changes, to automatically update the app, but I get no events.
This is the used code
streamListener() { log("listening"); device.notificationMessageStream.listen((event) { log("received event"); event.params?.forEach( (key, value) { switch (key) { case 'power': properties['power'] = value; } }, ); notifyListeners(); }); }

First log is showing up. Received event is not when changing device state from the same device or e.g. Google home.

Error when starting search without internet connection

Whenever my program is starting to search devices using yeedart without an internet connection I am getting this error

SocketException: Send failed (OS Error: Network is unreachable, errno = 101), address = 0.0.0.0, port = 1982

Not sure what is the expected behavior but let's discuss it.
I think it will be more appropriate to return empty results as if the package didn't find any device.

Support for Yeelink?

I have Yeelink (not Yeelight) bulb and the discover function can't find it.

I can see and control this bulb using the official Yeelight app.

Is adding Yeelink support something that we are thinking of adding to this package or is it a different thing that does not belong under yeedart vision?

Errro Yeelight.discover Null check operator used on a null value

While using the Yeelight.discover function I am getting

Null check operator used on a null value

Crash.

I have several smart devices in my home but currently it does not include any Yeelight devices.

The code is crashing inside

factory DiscoveryResponse.fromRawResponse(String rawResponse) {

and
rawResponse

Value is

M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1982
MAN: \"ssdp:discover\"
ST: wifi_bulb

Crashes on line 173

final match = regExp.firstMatch(rawResponse)!;

Tested devices list

I think it will be good to have Tested devices/supported devices list in the readme.

I want to buy a new yeelight product and I am not sure how to check if this is compatible with this device.

If the device is not detected during the discovery, I hope this will save someone's time.

I have 4 bulbs, but when running the discovery, the list always contains only one element.
Initially, I thought that perhaps these are different models using a modified protocol.
After a brief search, I discovered the following: for your device to be visible during scanning, it MUST be enabled in the official Yeeligh application. The option is called Lan Control, and such an option is not available in the Xiaomi SmartHome application, for example. You can read more about it here, https://getyeti.webflow.io/posts/how-to-control-yeelight-and-your-smarthome-with-yeti, but I'll duplicate it because links on the internet are not always reliable.

  1. Tap on your light
  2. Tap on the arrow to open an option menu (eject icon)
  3. Now select the LAN Control option
  4. Finally, enable the LAN Control by tapping on the switch. It will become green once the LAN control is enabled.

Immediately after enabling this option, the device will be detected.
Снимок экрана от 2024-02-04 13-38-25

colorTemperature question

In the documentation of the code it is written that

/// * [colorTemperature] - target color temperature (1700 - 6500 K).

What will happen if I will execute setColorTemperature with color temperature smaller than 1700 or bigger than 6500?.

Will it round it to the closes similar value or the request will fail to change the color temperature at all?.

Discover may not work if computer connected to multiple networks

I am running dart native on Linux computer.

Yeelight.discover() not working whenever my computer is connected to different LAN and WiFi network at the same time.
After disconnecting from the LAN network the discover() find my Yeelight device.

image

This is low priority bug.

Broken pipe

when send any command (like on/off') i get next error

Error : SocketException: Broken pipe (OS Error: Broken pipe, errno = 32)

I'm checking bulb.isConnected before sending command and its true

Can't find my yeelights

Hello!

First of all thank you for making this package!
I'm not sure why but I can't find any lights, they have LAN control on. Checked on android and windows. Played around with different timeout settings but I can't seem to find the problem.
This is the code I'm using right now: final response = await Yeelight.discover(timeout: Duration(seconds: 10));

Hope you can help me!

Empty result from .discover()

Hi.

I'm relatively new to Dart so it might be just me, but i can't get the .discover() method to work correctly.

For instance:

Future<void> _fetchLights() async { List<DiscoveryResponse> devices = await Yeelight.discover(); print(devices); }

always shows an empty array, even with a 30s timeout.
All of my lights have LAN control enabled and I can control them with the library through their IPs, but I can't discover them through my Flutter app.

Am i doing something wrong, or maybe it is a dev environment issue ?

The story behind this package

As I am creating smart Hub in dart I will definitely try this package and probably (if it is working) include it to add support for ‏Yeelight devices.

It will save me a lot of work so first of all many thanks.

Would love to hear why did you started this package.
What devices where tested.

If you know other dart packages to control smart devices products please let me know.

Unexpected character

Sometimes when calling await device.turnOn(); I am getting this error

I/flutter (13754): Error :  FormatException: Unexpected character (at line 2, character 1)
I/flutter (13754): {"id":969402310,"result":["ok"]}

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.