woozar / node-red-contrib-time-based-dimmer

MIT License
4 stars 4 forks source link

Re-use input message #2

Closed bartbutenaers closed 4 years ago

bartbutenaers commented 4 years ago

Hi @Woozinator,

My best wishes for 2020!

In the following example flow, the input message contains RGB values:

image

[{"id":"b833968a.fdbcc8","type":"inject","z":"ad3d4cf9.f7213","name":"brightness_up","topic":"","payload":"brightness_up","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":330,"y":420,"wires":[["3317ab86.504a04"]]},{"id":"ee50b2d9.9a29c","type":"inject","z":"ad3d4cf9.f7213","name":"brightness_down","topic":"","payload":"brightness_down","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":460,"wires":[["3317ab86.504a04"]]},{"id":"533def95.79798","type":"time-based-dimmer","z":"ad3d4cf9.f7213","name":"","interval":"500","step":"10","minValue":"10","maxValue":"40","startIncCommand":"brightness_up","stopIncCommand":"brightness_stop","startDecCommand":"brightness_down","stopDecCommand":"brightness_stop","x":780,"y":420,"wires":[["529262ed.f717fc"]]},{"id":"529262ed.f717fc","type":"debug","z":"ad3d4cf9.f7213","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":960,"y":420,"wires":[]},{"id":"a6fa2a19.59b4d8","type":"inject","z":"ad3d4cf9.f7213","name":"brightness_stop","topic":"","payload":"brightness_stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":340,"y":500,"wires":[["3317ab86.504a04"]]},{"id":"3317ab86.504a04","type":"change","z":"ad3d4cf9.f7213","name":"Set RGB values","rules":[{"t":"set","p":"red","pt":"msg","to":"30","tot":"num"},{"t":"set","p":"green","pt":"msg","to":"80","tot":"str"},{"t":"set","p":"blue","pt":"msg","to":"200","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":580,"y":420,"wires":[["533def95.79798"]]}]

Currently the output message only contains your dimmer value in the payload, but our RGB values are thrown away. Which is normal behaviour, since you create a new object from scratch:

send({ payload: newValue })

It would be nice if your output message could be based on the input message, so our input message data would be kept unchanged (apart from the payload content of course).

If you would agree to implement that, I 'think' you can do it like this:

Remark: the cloning is really required! If you would pass the same input message N times to the output, this would result in very weird effects. Because you would end up with N references to the same message object. So at every tick you would end up overwriting the previous value (in the same msg object)!

Thanks again for your time! Bart

woozar commented 4 years ago

I can understand your idea behind this request, but I am sorry to disagree. The settings are already complicated enough and I would rather not make them even more complicated. Also all the nodes, that I have used so far use the same approach es my node does.

If there is a bigger group of people all requesting this change I might reconsider, but for the moment I will not change it. Maybe you can use a subflow to create one node, that has got the desired behavior. https://nodered.org/docs/user-guide/editor/workspace/subflows

SalkinDK commented 4 years ago

@bartbutenaers Just found this fantastic node, but ran into the same problem as you. Can i ask if you found a solution? And of course thanks alot to the creator of the node.

bartbutenaers commented 4 years ago

Hi @SalkinDK, Unfortunately I had no time yet to build my own solution. Bart

SalkinDK commented 4 years ago

@bartbutenaers ok, i tried to fiddle around with it yesterday. My workaround is to put the dimmer node into a subflow. in the subflow i store the info i need, in my case the entity of the lamp in hass, as a flow variable then run through the dimmer node and on the other side restore the flow variable before sending the payload.

Hope it can help somebody in the same situation. :)