ottoszika / node-red-contrib-ewelink

NodeRED nodes for eWeLink smart devices

Home Page:https://ottoszika.github.io/node-red-contrib-ewelink

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

It is possible to specify the deviceId only in the node config

ckhmer1 opened this issue · comments

Hi,
first of all, thanks for your great job.
I'd like to specify the deviceId inside the message sent to the node and not always inside the node itself, like msg.deviceId= .....
It should be a simple fix, in ewelink-connect.js, just replace the row:

evaluatedParams.unshift(deviceId);

with something following row:

evaluatedParams.unshift(deviceId || msg.deviceId ? msg.deviceId.trim() : '');

In this way it the deviceId is not specified inside the node configuration, it will use the one specified inside the message.
Do you agree with me?

Thanks
Claudio

Hey I'm also very interested in this functionality and would be keen to help test/implement.
I haven't looked at the surrounding code yet however that change looks perfectly acceptable.

I have Sonoff 4x POW / 4x BASIC / 4x TH10 (with sensors) devices, which all work currently. I plan to use it for the temp+Humidity, the instantaneous power would also be nice but future use.

Had some issues with that when I supplied params in the payload, ended up with unshift is not a function of evaluatedParams.

Have a new commit in my fork
#https://github.com/tyeth/node-red-contrib-ewelink/commits/master

If people are happy, I'll add the tests to the other modules (may anyway) and submit a pull request.

A simple flow attached:
[{"id":"7f47ff7.dac58","type":"tab","label":"Simple example","disabled":false,"info":""},{"id":"1983ed1a.255de3","type":"inject","z":"7f47ff7.dac58","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":120,"wires":[["c9c59ef1.afc35"]]},{"id":"884b0806.b7c4f8","type":"inject","z":"7f47ff7.dac58","name":"","topic":"","payload":"100021f5bf","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":260,"wires":[["673943a8.c850ec"]]},{"id":"aeb1427f.452e","type":"inject","z":"7f47ff7.dac58","name":"","topic":"","payload":"100021f4f1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":320,"wires":[["673943a8.c850ec"]]},{"id":"83921d4b.4cf6a","type":"debug","z":"7f47ff7.dac58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1060,"y":100,"wires":[]},{"id":"76c8c0b8.6049a","type":"debug","z":"7f47ff7.dac58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1100,"y":380,"wires":[]},{"id":"c9c59ef1.afc35","type":"ewelink-devices","z":"7f47ff7.dac58","name":"","auth":"c3925593.6b6ba8","x":600,"y":140,"wires":[["83921d4b.4cf6a"]]},{"id":"673943a8.c850ec","type":"change","z":"7f47ff7.dac58","name":"set msg.deviceid = msg.payload","rules":[{"t":"set","p":"deviceid","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":300,"wires":[["b339303b.8ec7f"]]},{"id":"b339303b.8ec7f","type":"ewelink-temperature-humidity","z":"7f47ff7.dac58","name":"","deviceId":"","auth":"c3925593.6b6ba8","x":870,"y":320,"wires":[["76c8c0b8.6049a"]]},{"id":"c3925593.6b6ba8","type":"ewelink-credentials","z":""}]

Hi,
sorry for the late reply,
you should replace the following rows:

    // First parameter should be always the device ID
    evaluatedParams.unshift(deviceId);

with

    let device_id = '';
    if (deviceId) {
      device_id = deviceId;
    } else if (typeof msg.deviceId !== "undefined") {
      device_id = msg.deviceId || '';
    }
    // First parameter should be always the device ID
    evaluatedParams.unshift(device_id);

You can also change the following line:

    node.send({ payload: result });

with the following line:

    node.send({ deviceId: device_id, payload: result });

to have the deviceId also in the output message.

An example of flow could be the following:

[{"id":"1983ed1a.255de3","type":"inject","z":"7f47ff7.dac58","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":40,"wires":[["c9c59ef1.afc35"]]},{"id":"884b0806.b7c4f8","type":"inject","z":"7f47ff7.dac58","name":"","props":[{"p":"deviceId","v":"100021f5bf","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{"params":[]}","payloadType":"json","x":110,"y":100,"wires":[["b339303b.8ec7f"]]},{"id":"aeb1427f.452e","type":"inject","z":"7f47ff7.dac58","name":"","props":[{"p":"deviceId","v":"100021f4f1","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ "params": [] }","payloadType":"json","x":110,"y":140,"wires":[["b339303b.8ec7f"]]},{"id":"83921d4b.4cf6a","type":"debug","z":"7f47ff7.dac58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":510,"y":40,"wires":[]},{"id":"76c8c0b8.6049a","type":"debug","z":"7f47ff7.dac58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":570,"y":120,"wires":[]},{"id":"c9c59ef1.afc35","type":"ewelink-devices","z":"7f47ff7.dac58","name":"","auth":"","x":290,"y":40,"wires":[["83921d4b.4cf6a"]]},{"id":"b339303b.8ec7f","type":"ewelink-temperature-humidity","z":"7f47ff7.dac58","name":"","deviceId":"","auth":"","x":330,"y":120,"wires":[["76c8c0b8.6049a"]]},{"id":"7348001d.8001d","type":"inject","z":"7f47ff7.dac58","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ "params": [] }","payloadType":"json","x":110,"y":180,"wires":[["b339303b.8ec7f"]]}]

Best Regards
Claudio