Don't know how to pull flow context without quotations in a template

How might I setup this template node to pull flow.fmodeUpstairsSet without the " " marks in the payload?

Here's the template:
{"fmode":"{{flow.fmodeUpstairsSet}}"}

[{"id":"a5b99c87.21cf68","type":"inject","z":"5d29b44a.2f258c","name":"AUTO","topic":"","payload":"0","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":1260,"wires":[["e62db145.72aa5"]]},{"id":"479c9f32.5e7d98","type":"inject","z":"5d29b44a.2f258c","name":"AUTO/CIRCULATE","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":188,"y":1304,"wires":[["e62db145.72aa5"]]},{"id":"ddaff9a8.85193","type":"inject","z":"5d29b44a.2f258c","name":"ON","topic":"","payload":"2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":148,"y":1344,"wires":[["e62db145.72aa5"]]},{"id":"e62db145.72aa5","type":"change","z":"5d29b44a.2f258c","name":"fmodeUpstairsSet","rules":[{"t":"set","p":"fmodeUpstairsSet","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":1260,"wires":[["f7c7e871.cc649"]]},{"id":"f7c7e871.cc649","type":"template","z":"5d29b44a.2f258c","name":"Tstat format","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"fmode\":\"{{flow.fmodeUpstairsSet}}\"}","output":"json","x":750,"y":1260,"wires":[["39325305.8a42bc","a6ce4a77.9aff78"]]},{"id":"a6ce4a77.9aff78","type":"debug","z":"5d29b44a.2f258c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":910,"y":1320,"wires":[]}]

Errr ? maybe just remove them from the template ?

I get a bad string error.

That error is because you have it set to JSON syntax highlighting, which doesn't know about mustache syntax.

To me it looks like you're just trying to make a JS object with a property named fmode set to the value of flow.fmodeUpstairsSet?

why not just use a function node?

var msg = {fmode: flow.get("fmodeUpstairsSet")}
return msg;

or a change node...
image

I still get an error. It appear of how and where the fmode object is placed. It will only work by having the object under payload and without quotes around the value. Here is the curl command from the API

$ curl -d '{"fmode":2}' http://192.168.7.240/tstat
{“success”: 0}

I've setup a flow with your suggestions along withe the associated debug.

Here's the Flow

[{"id":"a628c702.609358","type":"http request","z":"5d29b44a.2f258c","name":"","method":"POST","ret":"obj","url":"http://192.168.7.240/tstat","tls":"","x":1230,"y":680,"wires":[["99dd4025.6fd1b","c004beb3.3f29e"]]},{"id":"bfbf802b.a54658","type":"template","z":"5d29b44a.2f258c","name":"{\"fmode\":2}","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"fmode\":2}","output":"json","x":970,"y":840,"wires":[["a628c702.609358","da227757.3a62c8"]]},{"id":"79e51d0c.be4bd4","type":"inject","z":"5d29b44a.2f258c","name":"inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":750,"y":980,"wires":[["599f6680.0d5188"]]},{"id":"a5b99c87.21cf68","type":"inject","z":"5d29b44a.2f258c","name":"AUTO","topic":"","payload":"0","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":750,"y":1080,"wires":[["e62db145.72aa5"]]},{"id":"479c9f32.5e7d98","type":"inject","z":"5d29b44a.2f258c","name":"AUTO/CIRCULATE","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":788,"y":1124,"wires":[["e62db145.72aa5"]]},{"id":"ddaff9a8.85193","type":"inject","z":"5d29b44a.2f258c","name":"ON","topic":"","payload":"2","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":748,"y":1164,"wires":[["e62db145.72aa5"]]},{"id":"e62db145.72aa5","type":"change","z":"5d29b44a.2f258c","name":"fmodeUpstairsSet","rules":[{"t":"set","p":"fmodeUpstairsSet","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":1080,"wires":[[]]},{"id":"99dd4025.6fd1b","type":"delay","z":"5d29b44a.2f258c","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1620,"y":680,"wires":[["26b5c9ed.41229e"]]},{"id":"599f6680.0d5188","type":"change","z":"5d29b44a.2f258c","name":"Set fmodeUpstairsSet","rules":[{"t":"set","p":"object","pt":"msg","to":"fmodeUpstairsSet","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":980,"wires":[["a628c702.609358","576cf85.e295b08"]]},{"id":"989eefbb.70d168","type":"function","z":"5d29b44a.2f258c","name":"var msg = {fmode: flow.get(\"fmodeUpstairsSet\")}","func":"var msg = {fmode: flow.get(\"fmodeUpstairsSet\")}\nreturn msg;","outputs":1,"noerr":0,"x":1090,"y":1020,"wires":[["a628c702.609358","549c4c27.1d3f6c"]]},{"id":"6d60e09a.cc56","type":"inject","z":"5d29b44a.2f258c","name":"inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":750,"y":1020,"wires":[["989eefbb.70d168"]]},{"id":"a2572035.7f37c8","type":"inject","z":"5d29b44a.2f258c","name":"inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":750,"y":840,"wires":[["bfbf802b.a54658"]]},{"id":"a982d857.98ca28","type":"template","z":"5d29b44a.2f258c","name":"{\"fmode\":\"{{flow.fmodeUpstairsSet}}\"}","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"fmode\":\"{{flow.fmodeUpstairsSet}}\"}","output":"json","x":1050,"y":940,"wires":[["a628c702.609358","a4e28019.4f1d9"]]},{"id":"d2c6b866.3b9b18","type":"inject","z":"5d29b44a.2f258c","name":"inject","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":750,"y":940,"wires":[["a982d857.98ca28"]]},{"id":"e1b2eca4.c998c8","type":"comment","z":"5d29b44a.2f258c","name":"Working","info":"","x":960,"y":800,"wires":[]},{"id":"1cf3709d.bb4907","type":"comment","z":"5d29b44a.2f258c","name":"Not Working","info":"","x":970,"y":900,"wires":[]},{"id":"da227757.3a62c8","type":"debug","z":"5d29b44a.2f258c","name":"{\"fmode\":2}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1390,"y":840,"wires":[]},{"id":"a4e28019.4f1d9","type":"debug","z":"5d29b44a.2f258c","name":"{\"fmode\":\"{{flow.tmodeUpstairsSet}}\"}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1470,"y":920,"wires":[]},{"id":"576cf85.e295b08","type":"debug","z":"5d29b44a.2f258c","name":"Set fmodeUpstairsSet","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1420,"y":980,"wires":[]},{"id":"549c4c27.1d3f6c","type":"debug","z":"5d29b44a.2f258c","name":"var msg = {fmode: flow.get(\"fmodeUpstairsSet\")}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1510,"y":1020,"wires":[]}]

Please forgive my ignorance on this and thank you for your patience. I'll be sure to contribute the complete flow for this project once I work out the bugs.

What is the inject sending to the function node? Put a debug on everything. You'll figure it out.

The function created an error as shown above.
What I don't know how to do it get the value of the fmode to the object of the payload without quotes. Here's a working version printed from debug. But I am limited to the number 2 instead of the variable.
200

Thank you. I've updated the post above with your recommendation.

export it again from node-red.

three backticks: `

code

three backticks: `

done with the ``` Thanks

I cleaned up the flow to improve testing and show the debug for each solution presented.

[{"id":"a628c702.609358","type":"http request","z":"5d29b44a.2f258c","name":"","method":"POST","ret":"obj","url":"http://192.168.7.240/tstat","tls":"","x":1650,"y":1020,"wires":[["99dd4025.6fd1b","c004beb3.3f29e"]]},{"id":"bfbf802b.a54658","type":"template","z":"5d29b44a.2f258c","name":"{\"fmode\":2}","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"fmode\":0}","output":"json","x":970,"y":980,"wires":[["a628c702.609358","2c4ecd0d.e3871a"]]},{"id":"a5b99c87.21cf68","type":"inject","z":"5d29b44a.2f258c","name":"AUTO","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":750,"y":1140,"wires":[["e62db145.72aa5"]]},{"id":"ddaff9a8.85193","type":"inject","z":"5d29b44a.2f258c","name":"ON","topic":"","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":750,"y":1180,"wires":[["e62db145.72aa5"]]},{"id":"e62db145.72aa5","type":"change","z":"5d29b44a.2f258c","name":"fmodeUpstairsSet","rules":[{"t":"set","p":"fmodeUpstairsSet","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":950,"y":1140,"wires":[["a982d857.98ca28"]]},{"id":"599f6680.0d5188","type":"change","z":"5d29b44a.2f258c","name":"Set fmodeUpstairsSet","rules":[{"t":"set","p":"fmode","pt":"msg","to":"fmodeUpstairsSet","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1180,"y":1220,"wires":[["a628c702.609358","576cf85.e295b08"]]},{"id":"989eefbb.70d168","type":"function","z":"5d29b44a.2f258c","name":"var msg = {fmode: flow.get(\"fmodeUpstairsSet\")}","func":"var msg = {fmode: flow.get(\"fmodeUpstairsSet\")}\nreturn msg;","outputs":1,"noerr":0,"x":1270,"y":1260,"wires":[["a628c702.609358","549c4c27.1d3f6c"]]},{"id":"a2572035.7f37c8","type":"inject","z":"5d29b44a.2f258c","name":"AUTO","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":750,"y":980,"wires":[["bfbf802b.a54658"]]},{"id":"a982d857.98ca28","type":"template","z":"5d29b44a.2f258c","name":"{\"fmode\":\"{{flow.fmodeUpstairsSet}}\"}","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"fmode\":\"{{flow.fmodeUpstairsSet}}\"}","output":"json","x":1230,"y":1180,"wires":[["a628c702.609358","a4e28019.4f1d9"]]},{"id":"e1b2eca4.c998c8","type":"comment","z":"5d29b44a.2f258c","name":"Working","info":"","x":960,"y":940,"wires":[]},{"id":"1cf3709d.bb4907","type":"comment","z":"5d29b44a.2f258c","name":"Not Working","info":"","x":970,"y":1100,"wires":[]},{"id":"da227757.3a62c8","type":"debug","z":"5d29b44a.2f258c","name":"{\"fmode\":2}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1230,"y":1020,"wires":[]},{"id":"a4e28019.4f1d9","type":"debug","z":"5d29b44a.2f258c","name":"{\"fmode\":\"{{flow.tmodeUpstairsSet}}\"}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1650,"y":1180,"wires":[]},{"id":"576cf85.e295b08","type":"debug","z":"5d29b44a.2f258c","name":"Set fmodeUpstairsSet","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1600,"y":1220,"wires":[]},{"id":"549c4c27.1d3f6c","type":"debug","z":"5d29b44a.2f258c","name":"var msg = {fmode: flow.get(\"fmodeUpstairsSet\")}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1690,"y":1260,"wires":[]},{"id":"b0def615.782b48","type":"template","z":"5d29b44a.2f258c","name":"{\"fmode\":0}","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"fmode\":2}","output":"json","x":970,"y":1020,"wires":[["a628c702.609358","da227757.3a62c8"]]},{"id":"8537bdbc.4363e","type":"inject","z":"5d29b44a.2f258c","name":"ON","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":750,"y":1020,"wires":[["b0def615.782b48"]]},{"id":"2c4ecd0d.e3871a","type":"debug","z":"5d29b44a.2f258c","name":"{\"fmode\":0}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1230,"y":980,"wires":[]},{"id":"90d2c30a.5756d","type":"inject","z":"5d29b44a.2f258c","name":"AUTO","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":750,"y":1220,"wires":[["15e51fc6.be5b28"]]},{"id":"239c4ff9.ae037","type":"inject","z":"5d29b44a.2f258c","name":"ON","topic":"","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":750,"y":1260,"wires":[["15e51fc6.be5b28"]]},{"id":"15e51fc6.be5b28","type":"change","z":"5d29b44a.2f258c","name":"fmodeUpstairsSet","rules":[{"t":"set","p":"fmodeUpstairsSet","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":950,"y":1220,"wires":[["599f6680.0d5188"]]},{"id":"ebe353a4.fbe03","type":"inject","z":"5d29b44a.2f258c","name":"AUTO","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":750,"y":1300,"wires":[["29e3ec7.2569d94"]]},{"id":"29e3ec7.2569d94","type":"change","z":"5d29b44a.2f258c","name":"fmodeUpstairsSet","rules":[{"t":"set","p":"fmodeUpstairsSet","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":950,"y":1300,"wires":[["989eefbb.70d168"]]}]

Much better now. Well done. Now it is easier to provide some suggestions.

Check if the revised nodes work well now.

[{"id":"c23faefa.34bc7","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"2a694971.719046","type":"template","z":"c23faefa.34bc7","name":"{\"fmode\":2}","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"fmode\":0}","output":"json","x":270,"y":100,"wires":[["e8c7847a.da2da8"]]},{"id":"3987e9df.770006","type":"inject","z":"c23faefa.34bc7","name":"AUTO","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":260,"wires":[["1ed828f8.624227"]]},{"id":"5c9f7e9f.87101","type":"inject","z":"c23faefa.34bc7","name":"ON","topic":"","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":300,"wires":[["1ed828f8.624227"]]},{"id":"1ed828f8.624227","type":"change","z":"c23faefa.34bc7","name":"fmodeUpstairsSet","rules":[{"t":"set","p":"fmodeUpstairsSet","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":260,"wires":[["e3bbd124.13fee"]]},{"id":"b4c6bbed.4ed288","type":"change","z":"c23faefa.34bc7","name":"revised2","rules":[{"t":"set","p":"fmode","pt":"msg","to":"fmodeUpstairsSet","tot":"flow"},{"t":"set","p":"payload","pt":"msg","to":"{\"fmode\" : fmode}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":340,"wires":[["e9397e36.895ef"]]},{"id":"d4c51efd.e2ec6","type":"function","z":"c23faefa.34bc7","name":"revised3","func":"msg.payload = {fmode: flow.get(\"fmodeUpstairsSet\")}\n\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":380,"wires":[["fc8df22b.a27"]]},{"id":"a6852b8d.66f828","type":"inject","z":"c23faefa.34bc7","name":"AUTO","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":90,"y":100,"wires":[["2a694971.719046"]]},{"id":"e3bbd124.13fee","type":"template","z":"c23faefa.34bc7","name":"revised1","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"fmode\":{{flow.fmodeUpstairsSet}}}","output":"json","x":440,"y":300,"wires":[["7b867e.3d569984"]]},{"id":"856f0381.1e481","type":"comment","z":"c23faefa.34bc7","name":"Working","info":"","x":260,"y":60,"wires":[]},{"id":"cc9ebd54.c81ab","type":"comment","z":"c23faefa.34bc7","name":"???","info":"","x":250,"y":220,"wires":[]},{"id":"f27bcd77.2233","type":"debug","z":"c23faefa.34bc7","name":"{\"fmode\":2}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":140,"wires":[]},{"id":"7b867e.3d569984","type":"debug","z":"c23faefa.34bc7","name":"{\"fmode\":\"{{flow.tmodeUpstairsSet}}\"}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":950,"y":300,"wires":[]},{"id":"e9397e36.895ef","type":"debug","z":"c23faefa.34bc7","name":"Set fmodeUpstairsSet","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":900,"y":340,"wires":[]},{"id":"fc8df22b.a27","type":"debug","z":"c23faefa.34bc7","name":"var msg = {fmode: flow.get(\"fmodeUpstairsSet\")}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":990,"y":380,"wires":[]},{"id":"3905345a.2a600c","type":"template","z":"c23faefa.34bc7","name":"{\"fmode\":0}","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"fmode\":2}","output":"json","x":270,"y":140,"wires":[["f27bcd77.2233"]]},{"id":"eca3a052.69663","type":"inject","z":"c23faefa.34bc7","name":"ON","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":"","x":90,"y":140,"wires":[["3905345a.2a600c"]]},{"id":"e8c7847a.da2da8","type":"debug","z":"c23faefa.34bc7","name":"{\"fmode\":0}","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":530,"y":100,"wires":[]},{"id":"7cdee0f1.f8aec","type":"inject","z":"c23faefa.34bc7","name":"AUTO","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":340,"wires":[["665cd1d7.28e1e"]]},{"id":"f1c5e8cb.c7c6b8","type":"inject","z":"c23faefa.34bc7","name":"ON","topic":"","payload":"2","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":380,"wires":[["665cd1d7.28e1e"]]},{"id":"665cd1d7.28e1e","type":"change","z":"c23faefa.34bc7","name":"fmodeUpstairsSet","rules":[{"t":"set","p":"fmodeUpstairsSet","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":340,"wires":[["b4c6bbed.4ed288"]]},{"id":"9492797a.598f98","type":"inject","z":"c23faefa.34bc7","name":"AUTO","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":420,"wires":[["acab3ccc.91052"]]},{"id":"acab3ccc.91052","type":"change","z":"c23faefa.34bc7","name":"fmodeUpstairsSet","rules":[{"t":"set","p":"fmodeUpstairsSet","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":420,"wires":[["d4c51efd.e2ec6"]]}]

Edit : below node should work too. It reads the value from flow context using JSONata.

[{"id":"53045596.a5f5bc","type":"change","z":"c23faefa.34bc7","name":"revised4","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"fmode\" : $flowContext(\"fmodeUpstairsSet\")}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":340,"wires":[["e9397e36.895ef"]]}]

Probably there are many other variations.

All four variations worked!! Thank you. Thank you. I'll finish building out the rest of the API to work with Node Red to share with the forum.

Your help is appreciated.

1 Like

I made good on my promise to pay it back. Here's the complete flow on the CT-50. Again... Thank you for your help.

2 Likes