npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yeelight-ts

v0.0.7

Published

A TypeScript library for controlling Yeelight smart devices over your local network.

Downloads

19

Readme

Yeelight TypeScript API Wrapper

Author: Gurel Ben Shabat (https://github.com/gurelbs)

This package provides a robust TypeScript library for controlling Yeelight smart devices over your local network. It simplifies the process of device discovery and command transmission, leveraging Node.js and TypeScript for a type-safe, event-driven architecture.

Features

  • Device Discovery: Automatically locate Yeelight devices on your local network using SSDP.
  • Control Commands: Send commands to control power, brightness, color, and more.
  • Type Safety: Built with TypeScript for enhanced code reliability and maintainability.
  • Event-Driven: Utilizes Node.js's EventEmitter for real-time device interaction.
  • Easy Integration: Designed for easy integration into any Node.js or TypeScript project.

Installation

Install the package via npm:

npm install yeelight-ts

Usage

Here's how to get started with the Yeelight TypeScript API Wrapper:

1. Project Setup:

Create a new project directory and initialize a Node.js project:

mkdir yeelight
cd yeelight
npm init -y

2. Install Dependencies:

Install the yeelight-ts library and a development server like nodemon (optional, but recommended for automatic code reloading):

npm install yeelight-ts
npm install -g nodemon

3. Create an Entry Point:

Create a file named index.ts and add the following code:

import { Yeelight } from "yeelight-ts";

const yeelight = new Yeelight();
const IP = "192.168.x.x"; // Change this to your Yeelight's IP address

yeelight.setBrightness(IP, 50); // Example: Set brightness (1-100)

// Other control commands (uncomment to use):
// yeelight.setPower(IP, 'on'); // Turn on the light
// yeelight.setColorTemperature(IP, 6500); // Set cooler white
// yeelight.setRGB(IP, 0xFF0000);  // Set red color
// yeelight.setHSV(IP, 180, 100);  // Set purple color
// yeelight.setName(IP, 'Living Room Lamp'); // Set device name

4. Run the Application:

Start the application using nodemon for automatic code reloading during development:

nodemon index.ts

API Documentation

The Yeelight class provides the following methods:

  • sendDiscovery(): Sends a discovery message to find Yeelight devices on the network.
  • handleDiscoveryResponse(callback): Handles the discovery response from a Yeelight device and calls the provided callback function with the device information. (Refer to the source code for event-driven usage)
  • sendCommand(ip, method, params): Sends a command to a Yeelight device with the specified IP address, method, and parameters. Returns a promise that resolves to the command result.
  • setPower(ip, powerState, effect, duration): Sets the power state of a Yeelight device.
  • setBrightness(ip, brightness): Sets the brightness of a Yeelight device.
  • setColorTemperature(ip, temperature): Sets the color temperature of a Yeelight device.
  • setRGB(ip, rgb): Sets the RGB color of a Yeelight device.
  • setHSV(ip, hue, sat): Sets the HSV color of a Yeelight device.
  • setName(ip, name): Sets the name of a Yeelight device.
  • isInRange(value): Checks if a value is within the valid range (1-100).

Note: This is a basic overview. Refer to the actual source code for detailed descriptions and parameter types.

Keywords

yeelight, smart-home, home-automation, lighting, smart-lighting, typescript, nodejs, yeelight-control, ssdp, iot, internet-of-things, smart-bulbs, yeelight-sdk, led-control, typescript-api