GithubHelp home page GithubHelp logo

Comments (7)

colinl avatar colinl commented on June 16, 2024

Do you mean you want it to close after any message or only the very first one it ever receives?

from node-red-contrib-simple-gate.

drmibell avatar drmibell commented on June 16, 2024

I suspect that the gate node may not be the best choice here. The filter (formerly rbe) node is designed specifically to eliminate repeated messages. You haven't said whether all of your messages are exactly identical. If the press, hold, and release messages can be distinguished, it should be fairly easy to get the sequence you want.

from node-red-contrib-simple-gate.

woytekbode avatar woytekbode commented on June 16, 2024

@colinl any first message it receives after starting or after re-opening with a reset command.

@drmibell thank you! I haven't come across the filter node yet, I will try it and see if it helps in this particular case. The messages have the same topic (deconz_event) but their payload is different. They have payload.event.id (device id) and payload.event.event (event id) so those can be used with a switch node to filter.

from node-red-contrib-simple-gate.

colinl avatar colinl commented on June 16, 2024

You can do what I think you want very easily just with a Change node (and the gate).

[{"id":"b10d142b.cec088","type":"inject","z":"eaa304df.eba478","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":1200,"wires":[["88590618.ffb2f8","8f8323b1.4a8d28"]]},{"id":"8f8323b1.4a8d28","type":"change","z":"eaa304df.eba478","name":"Close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":1240,"wires":[["88590618.ffb2f8"]]},{"id":"88590618.ffb2f8","type":"gate","z":"eaa304df.eba478","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memoryOnly","x":470,"y":1200,"wires":[["9ced743a.f6222"]]},{"id":"9ced743a.f6222","type":"debug","z":"eaa304df.eba478","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":1280,"wires":[]},{"id":"7391588c.712768","type":"inject","z":"eaa304df.eba478","name":"Open","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":1340,"wires":[["2328d32c.424294"]]},{"id":"2328d32c.424294","type":"change","z":"eaa304df.eba478","name":"Open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":1340,"wires":[["88590618.ffb2f8"]]}]

from node-red-contrib-simple-gate.

woytekbode avatar woytekbode commented on June 16, 2024

You can do what I think you want very easily just with a Change node (and the gate).

[{"id":"b10d142b.cec088","type":"inject","z":"eaa304df.eba478","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":1200,"wires":[["88590618.ffb2f8","8f8323b1.4a8d28"]]},{"id":"8f8323b1.4a8d28","type":"change","z":"eaa304df.eba478","name":"Close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":1240,"wires":[["88590618.ffb2f8"]]},{"id":"88590618.ffb2f8","type":"gate","z":"eaa304df.eba478","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memoryOnly","x":470,"y":1200,"wires":[["9ced743a.f6222"]]},{"id":"9ced743a.f6222","type":"debug","z":"eaa304df.eba478","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":1280,"wires":[]},{"id":"7391588c.712768","type":"inject","z":"eaa304df.eba478","name":"Open","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":1340,"wires":[["2328d32c.424294"]]},{"id":"2328d32c.424294","type":"change","z":"eaa304df.eba478","name":"Open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":1340,"wires":[["88590618.ffb2f8"]]}]

Absolutely right! Actually, that is the exact solution I'm using now. I think this might be a fairly common use case and the added functionality will reduce the addional change node and thus clutter. For one flow that's fine but for many switches in a typical home setup it would be a nice quality of life change.

@drmibell I just tried the suggested filter node and I think you are right. This node is a better fit for my purpose, thank you for pointing it out to me, I haven't come across it during my search for a good node. With the (rbe) filter node I can replace the change and gate nodes. And more importantly, I can use the filter node much earlier in the flow by placing it in front of the initial switch that filters the messages!

from node-red-contrib-simple-gate.

colinl avatar colinl commented on June 16, 2024

If you happen to have a function node immediately prior to the gate then, instead of the change node, you could replace the return msg at the end with

node.send(msg)
return {topic: "control", payload: "close"}

from node-red-contrib-simple-gate.

drmibell avatar drmibell commented on June 16, 2024

I am glad you have found ways to resolve your issue. I see the reason for your suggestion and feel that I should explain why I would rather not modify the gate node. First, I think I would be stepping onto a slippery slope. There has already been a request to close the gate for a specified length of time after passing the first message. I would also expect interest in keeping it closed for a certain number of messages after the first, and so on. All these cases can be managed easily with external logic, while modifying the node would add complexity to the user interface and to the node itself. Second, today's "clutter" is tomorrow's (or next year's) readability. I think that troubleshooting or modifying flows is much easier if the logic is exposed in the wiring and messages rather than buried in options that are visible only in the node's edit dialog. Finally, I have used a design approach for gate and its sister node queue-gate that I think has made them more useful and easier to troubleshoot. The messages that control the state of the gate are kept completely separate from the message traffic that is being controlled. This makes the state of the gate fully predictable and reproducible. This would not be case if messages passing through the gate, over which the user may have no real control, were allowed to change its state. This is a long comment, but I hope it helps you understand my thinking.

from node-red-contrib-simple-gate.

Related Issues (17)

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.