GithubHelp home page GithubHelp logo

jangxx / node-magichome Goto Github PK

View Code? Open in Web Editor NEW
124.0 124.0 26.0 96 KB

An incomplete implementation of the functionality of the "Magic Home" app. Partially a port of https://github.com/Danielhiversen/flux_led to Node.js

License: ISC License

JavaScript 100.00%

node-magichome's People

Contributors

edeuxk avatar egold555 avatar jaapenstaart avatar jangxx avatar jghaanstra avatar tedstriker avatar yerich avatar z81 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  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  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  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

node-magichome's Issues

Multi Device Support

Hi, can you please add a multi device config node so you can have more than one device in the network? :)

Support for new devices

Hey,
Thanks a lot for your library.

I was wondering if you have plans to support newer devices.
Devices like 'AK001-ZJ2146', 'AK001-ZJ2147', 'AK001-ZJ2148', 'HF-LPB100' are not working right now. (only on/off)

Flux_led got a lot of updates recently and supports these devices.

I already tried to make a few adaptions to this library(which adds support for above devices) but I don't have the knowledge of all the different buffers. (edited control.js)

Flux led models DB: https://github.com/Danielhiversen/flux_led/blob/master/flux_led/models_db.py

Looking forward to your answer :)

Works with blocked internet connection to the light?

Hi,

First of all- great project! Looking forward to using it & contributing to it.
I'm planning to buy an OFFDARKS ceiling light:
https://www.aliexpress.com/item/4000385532059.html
I'm assuming this light will work with this library as it's also using the Magic Home app.

I was just wondering if this library keeps working when I block internet access for the light in my router.
Do you expect that this library will still be able to control the light? I know it's using a LAN connection, but still- maybe it requires the lamp to be connected to the internet?

New type

image

  • turning it on/off works
  • setting pattern works
  • setting color does not work

Tried setting with ackMasks but it doesn't fix it. Is this type supported?

New type

Hello, I got a device of type 0x81 I think.

logs:

Received: 81 44 23 61 21 1f 00 00 00 fe 04 00 0f 9a 
{"type":68,"on":true,"mode":"color","speed":0,"color":{"red":0,"green":0,"blue":0},"warm_white":254,"cold_white":0}

Do you want me to run tests to check if we should add it to default mask applying ?
This device has color and warm white. the magic home app is setting the cold white by changing the rgb values i think (cold white always returns 0).

Set Color Issue

C:\Users\pierr\Documents\Chroma\commands\core\ping.js:29
light.setColor(green)
^

ReferenceError: green is not defined
at C:\Users\pierr\Documents\Chroma\commands\core\ping.js:29:28

i have this error D; can you send me how to set the correct color 

my code :
let light = new Control("192.168.0.103");
light.setPower(true).then(success => {
light.setColor(green)
});

Discovery Mode

What's up with the discovery mode?

I saw on the python repo that we have to scan the port 48899.

Do you want me to do it?

Poor discovery success rate

For some reason, the device discovery for me is performing very poorly, I'm able to discover my devices very rarely. I am looking to use this functionality, but could this be converted over to communicate purely over the local network? Or if not, is there any enhancements that could be done in the discovery.scan method?

new Type 0x35

Hello me again.
I got new bulbs, and this ones also have cold white (not the simulated one with rgb = 255)

When cold white and brightness at 100%:

{
  "type": 53,
  "on": true,
  "mode": "color",
  "speed": 50,
  "color": {
    "red": 0,
    "green": 0,
    "blue": 0
  },
  "warm_white": 0,
  "cold_white": 255
}

I can't figure out if I should use masks or not since turnOn/turnOff works like a charm but setColor always set the bulb in warm white mode.

I'm avalaible to run tests after work hours ( Central European Time + 1 )

Error on a few commands in cli.js

I get the following error when I run commands like list_patterns, discover and help:

PS C:\Users\bleep> magic-home list_patterns
C:\Users\bleep\AppData\Roaming\npm\node_modules\magic-home\cli.js:84
if (args.length > command.args.length) { ^

TypeError: Cannot read property 'length' of undefined
at Object. (C:\Users\bleep\AppData\Roaming\npm\node_modules\magic-home\cli.js:84:32)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

I'm on Win 10, PowerShell with a fresh node.js/npm install.

Failed to repair

After i reboot homey or my router, al my devices are unreachable. The magic home app can find the device, maybe because a new ip adres or something. Can you lock the device on a mac adress?

timeoutproblem

Hi my peogram crash for timeout .... i use your module for sync my device razer with my led strip
error : C:\Users\pierr\Documents\Chroma\node_modules\magic-home\lib\Control.js:210
reject(new Error("Command timed out"));
^

Error: Command timed out
at Control._handleCommandTimeout (C:\Users\pierr\Documents\Chroma\node_modules\magic-home\lib\Control.js:210:12)
at Timeout._onTimeout (C:\Users\pierr\Documents\Chroma\node_modules\magic-home\lib\Control.js:237:12)
at listOnTimeout (node:internal/timers:557:17)
at processTimers (node:internal/timers:500:7)

my code :
const Chroma = require("razer-chroma-nodejs");
let currentColor;

const { Control, CustomMode } = require('magic-home');
let light = new Control("192.168.0.103");

/* Create effect */
const waveEffect = () => {
Chroma.effects.keyboard.wave(0, 5);

return setInterval(() => {
    const cellData = Chroma.effects.keyboard.getData();

    currentColor = cellData[cellData.length - 1];

    Chroma.effects.headset.setEffect("CHROMA_CUSTOM", [cellData[0].getColor(), cellData[cellData.length - 1].getColor(), 0, 0, 0]);
    Chroma.effects.mouse.setColor(cellData[cellData.length - 1].getColor());
    Chroma.effects.chromalink.setColor(cellData[cellData.length - 1].getColor());
}, 1);

};

light.setPower(true).then(success => {
// Load Chroma
Chroma.util.init(() => {
let effect = waveEffect();

    let ledEffect = setInterval(() => {
        light.setColor(currentColor.r, currentColor.g, currentColor.b);
    }, 70);

    setTimeout(() => {
        clearInterval(effect);
        clearInterval(ledEffect);
        Chroma.util.close();
    }, 10000);
});

});

[REQUEST] Set warm white mode

RGBW and RGBWW LED strips can also change the (warm) white of the LED strip. The Python library which was used to create this library supports a "set warm white mode" function but it seems this has not been ported to this nodejs library. I'd like to request this feature. I'd submit a PR myself but my programming skills are to limited.

light.setColor(r,g,b) sets ww to 100%

When using the light.setColor method on a RGBW LED strip using a Magic Home RGBW controller, the (warm) white setting is automatically set to 100%. Is this intended behaviour? I would assume only the RGB LED's would change to the given color and not also change the white leds.

Requests fail after first request

I've just discovered this and decided to try it out with my AK001-ZJ210. My lights only accept one request before refusing to serve anymore. The issue is resolved when the application is restarted. I don't know if there's something I'm missing, as I am pretty new to node.js. Any help is appreciated!

Error: Only got short reply

I would like to turnOn a LED stripe and immediately query the current state. With the code below, I'm facing a strange issue:

  • Without the sleeper function the returned color values are wrong. I guess this is nothing special as the controller has a "fancy startup animation" (although they are wrong as well when the light already is on)
  • With values around 500ms for the sleeper, I reproducible get a:
>node test.js
Received: f0 71 23 84
error: Only got short reply
  • With values significantly below (e.g. 0ms, 200ms etc) or over 500ms (e.g. 600ms+) the error is not observed
  • Maybe also noteworthy: With the short delays, the returned type is always 113, with the 600+ delays the type is 4

I'm I doing something wrong? I would appreciate if you could shed some light into this behavior.

const MagicHomeControl = require('magic-home').Control;
const ip = '192.168.178.74';
const controlOptions = {log_all_received: true, ack: {power: false, color: false, pattern: false, custom_pattern: false}};
const lampControl = new MagicHomeControl(ip, controlOptions);

const sleeper = function (ms) {
	const promise = new Promise(((resolve, reject) => {
		setTimeout(() => {
			resolve();
		}, ms);
	}));
	return promise;
};

lampControl.turnOn()
	.then(() => sleeper(500))
	.then(() => lampControl.queryState())
	.then(state => console.log('\n' + JSON.stringify(state) + '\n'))
	.catch(err => console.log('error: ' + err.message));

light.setColor callback very slow

For controlling my LED strips at home, I'm calling turnOff, turnOn, setColor and setColorWithBrightness functions. turnOff and turnOn finish quite fast (~3 sec), but setColor hangs for about 15 seconds before executing the callback, even though the light successfully changed color within the first 2-3 seconds.

Any way to improve this behaviour? The domoticz setup I'm using to execute the commands is not happy with scripts hanging for more than 10 seconds.

Scanning does not work

I have a Magic Home led controller, but scanning does not work. If I specify correct IP address I can control LEDs with this package, but scanning somehow does not work.

custom_mode_test.js doesn't work with WS2812b

Hello,

First of all, sorry if my english is poor.

I just clone this repo to use it with my LED and I juste try the custom_node_test.js and nothing happen on my strip

test@nas:~/node_modules/magic-home/examples# node custom_mode_test.js 192.168.0.96 success

If I try to use effect_test.js it work fine !

In my MagicHome App I have a custom mode
"Overlay from end to start" but it loop and I want to make it once, after that, I want it to be just on.
So I add a "Change quickly" step with the same Start Color & End Color but unfortunately, I can't set the speed to 0, so the two steps loop every minutes.
I assume that I can remake this with a custom_mode but for now, nothing happen when I launch the custom_mode_test.js

Do I forgot something ?

Thank you for reading me

Whenever changing light color on Light instance, only first change occurs.

I think there is something strange with the transport socket connection when changing lights, unless I am doing something wrong.

calling light.color() the first time works as expected, but then later if I call light.color() nothing happens, and in the queue property I see pnding promises has increased to 1, and in the transport socket I see connecting: false

Do you have any idea what is happening?

Logging light.color() appears the promise always remains pending... never resolves.

Edited ack mask still getting time out error

I have a model AK001-ZJ2101 Bulb, using the python library I was able to change color, but whenever I try to change the color I end up with the same error. I have changed the ack mask according to what did and didn't get a response, but I still got the same errors

Code that I used
const { Control } = require('magic-home');

let light = new Control("192.168.1.177")
// light.turnOff()
light.turnOn()
light.setColor(255,0,0)
light.setColorAndWarmWhite(255,0,0,13)
light.setColorAndWhites(255,0,0,13,13)`
const { Control } = require('magic-home');

at Control._handleCommandTimeout (C:\Users\XXX\Documents\Code\JavaScript\HAL\Trial Folder\node_modules\magic-home\lib\Control.js:217:12)
at Timeout._onTimeout (C:\Users\XXX\Documents\Code\JavaScript\HAL\Trial Folder\node_modules\magic-home\lib\Control.js:244:12)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
(Use node --trace-warnings ... to show where the warning was created)
(node:15640) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:15640) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:15640) UnhandledPromiseRejectionWarning: Error: Command timed out
at Control._handleCommandTimeout (C:\Users\Helquin\Documents\Code\JavaScript\HAL\Trial Folder\node_modules\magic-home\lib\Control.js:217:12)
at Timeout._onTimeout (C:\Users\Helquin\Documents\Code\JavaScript\HAL\Trial Folder\node_modules\magic-home\lib\Control.js:244:12)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
(node:15640) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:15640) UnhandledPromiseRejectionWarning: Error: Command timed out
at Control._handleCommandTimeout (C:\Users\XXX\Documents\Code\JavaScript\HAL\Trial Folder\node_modules\magic-home\lib\Control.js:217:12)
at Timeout._onTimeout (C:\Users\XXX\Documents\Code\JavaScript\HAL\Trial Folder\node_modules\magic-home\lib\Control.js:244:12)
at listOnTimeout (internal/timers.js:557:17)
at processTimers (internal/timers.js:500:7)
(node:15640) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 3)

Is candle supported?

I just received some magic home bulbs and in the app there is an option for candle where you can set amplitude, brightness, speed and color/CCT.

Buffer difference for `setColor` command?

I'm attempting to use this library to control a set of light bulbs on my LAN. For my bulbs (the BERENNIS Smart Light Bulb) most of the commands work, but setColor and all other color-related functions do not.

Using Wireshark I saw that the python library, for the same command, was sending 0x31, red, green, blue, ww, 0xf0, 0x0f. This library sends 0x31, red, green, blue, ww, 0, 0x0f.

I'm not sure why there is a difference; it could be the type of bulb or something. Just wanted to record what I found in case it helps anyone else.

Cannot change warmwhite values when using effectMode

I want to change the amount of the warm light on my Ledstrip while using effectMode, but i getting the following error. Even though this.setColor(r,g,b) works flawlessly.

const { Control } = require('magic-home');
const control = new Control("192.168.0.234");

control.startEffectMode().then(effects => {
	effects.start(interval_function);
}).catch(err => {
	console.log("Error while connecting:", err.message);
});

function interval_function() {
	return this.setColorAndWarmWhite(255, 0, 0,255); 
}
TypeError: this.setColorAndWarmWhite is not a function
    at EffectInterface.interval_function [as _interval_function] (C:\Users\lamec\Desktop\Tisch\effect.js:19:15)
    at Timeout.setTimeout [as _onTimeout] (C:\Users\lamec\Desktop\Tisch\node_modules\magic-home\lib\EffectInterface.js:86:29)
    at ontimeout (timers.js:466:11)
    at tryOnTimeout (timers.js:304:5)
    at Timer.listOnTimeout (timers.js:267:5)

Also the normal Mode works flawlessly with this.setColorAndWarmWhite(r,g,b)

const { Control } = require('magic-home');
 
let light = new Control("192.168.0.234");
light.setColorAndWarmWhite(255,0,0,255);

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.