Sending slider value inside template

Is it possible to send a variable in response to get request ????

[{"id":"1c7fe071.dd4f98","type":"tab","label":"api sim","disabled":false,"info":""},{"id":"42d886d.2fab478","type":"http in","z":"1c7fe071.dd4f98","name":"","url":"hello","method":"get","upload":false,"swaggerDoc":"","x":310,"y":280,"wires":[["b67cda5d.60cae"]]},{"id":"b67cda5d.60cae","type":"template","z":"1c7fe071.dd4f98","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"mustache","template":"{\"payload\":50}","output":"str","x":610,"y":300,"wires":[["1c83adb8.a01502"]]},{"id":"1c83adb8.a01502","type":"http response","z":"1c7fe071.dd4f98","name":"","statusCode":"","headers":{},"x":1040,"y":300,"wires":[]}]

If i understand your query, yes

e.g.

[{"id":"bc6aee81.3a1f3","type":"http in","z":"6fcc3140.459a2","name":"","url":"hello","method":"get","upload":false,"swaggerDoc":"","x":270,"y":240,"wires":[["8953ca4f.f212a"]]},{"id":"90279a5b.bfc3a8","type":"ui_slider","z":"6fcc3140.459a2","name":"slider","label":"slider","tooltip":"","group":"165e1e1a.e752fa","order":1,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":0,"max":"100","step":"5","x":380,"y":320,"wires":[["fbf435a6.35b9e8"]]},{"id":"8953ca4f.f212a","type":"change","z":"6fcc3140.459a2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"slider","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":240,"wires":[["b0b64c93.b81398"]]},{"id":"fbf435a6.35b9e8","type":"change","z":"6fcc3140.459a2","name":"","rules":[{"t":"set","p":"slider","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":320,"wires":[["9dc7ea0f.e862b8"]]},{"id":"b0b64c93.b81398","type":"http response","z":"6fcc3140.459a2","name":"","statusCode":"","headers":{},"x":710,"y":240,"wires":[]},{"id":"9dc7ea0f.e862b8","type":"debug","z":"6fcc3140.459a2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":320,"wires":[]},{"id":"e3fc91f5.c1d078","type":"inject","z":"6fcc3140.459a2","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":250,"y":320,"wires":[["90279a5b.bfc3a8"]]},{"id":"165e1e1a.e752fa","type":"ui_group","z":"","name":"Default","tab":"f9b58883.fa613","order":1,"disp":true,"width":"12","collapse":false},{"id":"f9b58883.fa613","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
1 Like

thanks alot dude you made my day . i was trying to deserialize Json response in ESP32 and getting the value of slider as long received in esp32 , i made some changes her is the prototype:

[{"id":"88b25812.a52fd8","type":"http in","z":"c043cf8e.9fbab","name":"","url":"hello","method":"get","upload":false,"swaggerDoc":"","x":540,"y":480,"wires":[["6548ad5d.850b5c"]]},{"id":"fd29bab0.a3fe38","type":"ui_slider","z":"c043cf8e.9fbab","name":"slider","label":"slider","tooltip":"","group":"4abde384.aad474","order":1,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":0,"max":"1000","step":"5","x":650,"y":560,"wires":[["3d324a4b.c8ee66"]]},{"id":"6548ad5d.850b5c","type":"change","z":"c043cf8e.9fbab","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"slider","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":480,"wires":[["815ecbfa.09d6c"]]},{"id":"3d324a4b.c8ee66","type":"change","z":"c043cf8e.9fbab","name":"","rules":[{"t":"set","p":"slider","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":560,"wires":[["e1622ee.a96b5d"]]},{"id":"a97be0e1.78358","type":"http response","z":"c043cf8e.9fbab","name":"","statusCode":"","headers":{},"x":1190,"y":480,"wires":[]},{"id":"e1622ee.a96b5d","type":"debug","z":"c043cf8e.9fbab","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1040,"y":560,"wires":[]},{"id":"126cf64f.d1b3ca","type":"inject","z":"c043cf8e.9fbab","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":520,"y":560,"wires":[["fd29bab0.a3fe38"]]},{"id":"815ecbfa.09d6c","type":"json","z":"c043cf8e.9fbab","name":"","property":"payload","action":"str","pretty":false,"x":960,"y":400,"wires":[["a97be0e1.78358","8f8a6a13.1fd968"]]},{"id":"8f8a6a13.1fd968","type":"debug","z":"c043cf8e.9fbab","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1340,"y":300,"wires":[]},{"id":"4abde384.aad474","type":"ui_group","z":"","name":"SENSORS","tab":"2b8559ab.f8b276","order":1,"disp":true,"width":"6","collapse":false},{"id":"2b8559ab.f8b276","type":"ui_tab","z":"","name":"HTTP","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

here is a photo from the the flow , i am trying in this project to exchange data between node red and ESP32 through GET/POST requests every 1 second and i will try to send data packet between both . i didn't like MQTT very much i find HTTP more flexible . does anyone have any idea why such a concept isn't common do i miss something ???? is there anyway also to send the variable value inside JSON object like this {"val" : payload } ??? i could send the response just by converting the payload to JSON

[{"id":"232bf664.c42c4a","type":"http in","z":"6fcc3140.459a2","name":"","url":"hello","method":"get","upload":false,"swaggerDoc":"","x":90,"y":580,"wires":[["5ef3947b.cea06c"]]},{"id":"5ef3947b.cea06c","type":"change","z":"6fcc3140.459a2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"slider\":$flowContext('slider')}","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":580,"wires":[["c7c1897c.129798","121c5c2c.a20bbc"]]},{"id":"c7c1897c.129798","type":"debug","z":"6fcc3140.459a2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":890,"y":400,"wires":[]},{"id":"121c5c2c.a20bbc","type":"http response","z":"6fcc3140.459a2","name":"","statusCode":"","headers":{},"x":740,"y":580,"wires":[]}]

you can create the object in the change node.

1 Like

thanks again , your help was tremendous .it is even faster now maybe because i was fetching the whole document before
doc.as<long>();

but now i am fetching the JSON object like this : doc["slider"].as<long>());
in which section in node red documentation is this way of accessing a value like {"slider":$flowContext('slider')} explained ????

It is explain in the JSONata site as the change node can use JSONata expressions

this is a text literal representation of a object, The $flowContext() is retrieving the value from context store.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.