linuxha / node-red-contrib-mytimeout

A dynamic count down timer for node-red
MIT License
10 stars 10 forks source link

Topic Using Mustache #27

Open dcplaya opened 4 years ago

dcplaya commented 4 years ago

Is it possible to allow mustache format in the setup of the node, such as setting the topic to be {{msg.topic}} and it would take the input topic and set the outgoing msg topic? Ideally this would apply to all input variables.

linuxha commented 4 years ago

I've not considered it and I'm not certain how to do it. Do you have any pointers?

I'm not saying no to the request. :-)

dcplaya commented 4 years ago

I am not sure how other nodes do it. I believe this line (line 49) for the Home Assistant node is grabbing the entity_id from the incoming node data though. Maybe this will help point you in the right direction?

https://github.com/zachowj/node-red-contrib-home-assistant-websocket/blob/e56a65bf5e3d15711f93da1d2c4c61d9e9001d7b/nodes/call-service/ui-call-service.js#L49

linuxha commented 4 years ago

Thanks I'll look into that.

linuxha commented 4 years ago

I think I have an idea now. I'll need to think this through.

Dcplaya, can you give me a mock sample json that you'd like processed? And what you expect mytimeout to do. Thanks

dcplaya commented 4 years ago

I'm thinking of trying to be object oriented. I know the timer currently can only be a single instance (which I am fine with) but I like to keep my topic through my entire flow as an identifier.

This is a quick sample JSON I threw together. I am currently building logic using your timer so I am sure it will expand as I keep building it up. Having the ability to override the on/off/warning messages as well would be a nice to have (and shouldn't be a bunch of extra work once you know how to do the topic override).

{"_msgid":"91d34935.9cc928","topic":"Bathroom Vanity Lights","payload":"on","timeout":1200,"warning":300}
linuxha commented 4 years ago

Okay {{msg.topic}} in the setup so that the above json will send to the topic: "Bathroom Vanity Lights"

Not sure how long this will take to code (no time budget at the moment).

fneudert commented 3 years ago

I think the easy way to keep the current topic if no other output topic is configured would be to do a topic = topic||msg.topic; in the on(msg) function.

linuxha commented 3 years ago

Wow, what a year. I've forgotten about this. I'll add it to my todo list now. Sorry about that, thanks for the reminder.

almostserious commented 3 years ago

Just wanted to comment that this is a great idea. Came here to see if this was already being asked. Ideally, all the settings of the node could also be just injected via JSON. i.e.: I would love to just set the timer off payload variably.

linuxha commented 3 years ago

I'm going to handle this in a few steps. At the moment I'm trying to grasp mocha so that I can incorporate all my tests. The manual test scripts take a long time to run and need to be verified manually. This makes them painful to run.

But in parallel I'll fix one other bug and I'll do something similar as to what fneudert suggested as the first step. I'll then add the support for {{mustache}}. I have to learn more about that. I suspect that I can get the first step soon. The second will take a bit longer as I'm also busy at work and need to do training on my own time (grrrr).