samuraitruong/yeelight

several function that i can make it works in JS

Closed this issue · 7 comments

Hi !

I can't make several function work in JS like setBright, scanByIp ...

here bellow a part of the code:

        const yeelight = new y.Yeelight({lightIp: req.params.lightIp, lightPort: lightPort});
        yeelight.connect().then((l) => {
            l.setBright(req.params.brightness, req.params.effect, req.params.duration).then(() => {
                l.disconnect();
                return res.status(200).send("Set Brightness command successful");
            });
        }).catch((e) => {
            return res.status(404).send(e);
        });

Can someone help me ? please

Thanks

HI @AnthonyIp , can you post the error? are all function not working or just a sub-set or command doesn't work?

@samuraitruong Hello, you can try it by cloning my repository =>
https://github.com/AnthonyIp/xiaomiApi

hi @AnthonyIp I haven't looked in your code but i can make a guess that req.params.xxx is string type

If you have looked in the yeelight code, some parameters are number and only work when you pass right data type in.

Could you please hardcode the value passed in and confirm it works?

Hi !
I tried parseInt(req.params.xxx) for those in int type but it still doesn't work.....

    setBright(req, res) {
        const yeelight = new y.Yeelight({lightIp: req.params.lightIp, lightPort: lightPort});
        yeelight.connect().then((l) => {
            l.setBright(parseInt(req.params.brightness), req.params.effect, parseInt(req.params.duration)).then(() => {
                l.disconnect();
                return res.status(200).send("Set Color HSV command successful");
            });
        }).catch((e) => {
            return res.status(404).send(e.message);
        });
    }

@samuraitruong my bad i found the issue ....It was my mistake
do you have any example code of how to use the functions cron*** ? setMusic?

thanks

hi @AnthonyIp , what was an issue?

you can see the comment for set musc here - https://github.com/samuraitruong/yeelight/blob/master/src/yeelight.ts#L300

You need to pass 3 parameters. The difficulty of this method is you have to have the broadcasting TCP server for your music

@samuraitruong It didn't check the type of the value ahaha.

How do you use the cron's function ?