ottoszika / node-red-contrib-ewelink

NodeRED nodes for eWeLink smart devices
https://ottoszika.github.io/node-red-contrib-ewelink
MIT License
48 stars 28 forks source link

[new feature] Enable setting deviceID dynamically #76

Open ndupont-net opened 4 years ago

ndupont-net commented 4 years ago

Hi, first of all thaks a bunch for providing this really promising plugin :) It will definitely help people have their first foray into home automation with Node Red :)

As I'm a lazy person, I would like to be able to get everything fully dynamic, and just use one single output node to control my devices.

Would it be possible to override the Device Id option with msg.deviceID ? It could be done either literally by specifying {{msg.deviceId}} in the config panel, or hidden in the node constructor somewhere.

I've tried both with no success, this is above my current node.js skills

Thanks !

Nicolas

ottoszika commented 4 years ago

Hello @ndupont-net ,

Thank you for your suggestion.

The current implementation is using a string payload. For example the Power State Output Node is received on, off or toggle. Using another structure will lead to a breaking change. I think there are two options:

  1. Allow both strings and object structures as input (minor version change)
  2. Allow only object structures (major version change)

Personally I would go with the first one.

The structure of a payload object for a specific device can be:

{
  "deviceId": "<Device ID>",
  "params": "<The old payload string>"
}

The structure of a payload object for a generic device can be:

{
  "deviceId": "<Device ID>",
  "method": "<Method Name>",
  "params": [<The parameters>]
}

The structures above are for output nodes. For input nodes (like state reading) we have no payload data for now, we need an input just to trigger the API. In this case we can set the payload directly to device ID, or we can use a structure like:

{
  "deviceId": "<Device ID>"
}

I think we can go with just a simple string for now representing the device ID.

In every situation the input device ID will override the configured one.

Let me know if this approach fits your needs.

Thanks, Otto

ndupont-net commented 4 years ago

Hi Otto, thanks a lot for that prompt answer.

Why change the payload structure at all ?

I might be missing something, but why not have msg = { payload : whatever , deviceID : "aa0011bb22" } ; ?

And adapt the constructor with something that would look like if(msg.deviceID) options.deviceID=msg.deviceID;

Thanks :)

Nicolas

ottoszika commented 4 years ago

Thanks for your suggestion @ndupont-net . I will implement this in the next release.

ndupont-net commented 4 years ago

Great !

majeka commented 1 year ago

Thanks for your suggestion @ndupont-net . I will implement this in the next release.

Hello! Please let me know if this is done or not? If so, how to correctly pass the dynamic parameters of the device id so that they work? @ottoszika

pmh1947 commented 1 year ago

For ndupont-net

.I had a similar problem when interfacing to Tado - solved by saving info to flow variables and  then combing info.

p xxx Sent from my phone, apologies for brevity and my dexterity inspired errors 😃

From: majeka @.***>

Sent: 24 May 2023 19:05:00 BST

To: ottoszika/node-red-contrib-ewelink @.***>

Cc: Subscribed @.***>

Subject: Re: [ottoszika/node-red-contrib-ewelink] [new feature] Enable setting deviceID dynamically (#76)

Thanks for your suggestion @ndupont-net https://github.com/ndupont-net . I will implement this in the next release.

Hello! Please let me know if this is done or not? If so, how to correctly pass the dynamic parameters of the device id so that they work?

— Reply to this email directly, view it on GitHub https://github.com/ottoszika/node-red-contrib-ewelink/issues/76#issuecomment-1561712482 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AZP7WMNT7V2IZYAN2HHCWX3XHZEUZANCNFSM4J7KNH6A . You are receiving this because you are subscribed to this thread.Message ID: @.***>