My first flows, thirst three work last one not

Hi, this is my first experience with nodered.
I am very impressed, after two hours i got the most important functionality working!

I want to use it mainly via:

Google Home - IFTT - NODERED - MQTT - Domoticz
Http get command - NODERED - MQTT - Domoticz

I have the tfirst working (see three flows in attachment
The last one, i cant get to work! Can anybody help a little bit?




[{"id":"87dcf813.641a68","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"43f91110.6822c","type":"mqtt out","z":"87dcf813.641a68","name":"mqtt_domoticz/in","topic":"domoticz/in","qos":"0","retain":"false","broker":"b47f58ae.8a7138","x":1230,"y":120,"wires":[]},{"id":"5ce99120.422b4","type":"inject","z":"87dcf813.641a68","name":"1005 aan","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["9e0e34cb.7f1c08"]]},{"id":"9e0e34cb.7f1c08","type":"function","z":"87dcf813.641a68","name":"Maak boodschap 1005 wii en tv lamp Aan","func":"msg.payload = {};\nmsg.payload.command = \"switchlight\";\nmsg.payload.idx = 1005;\nmsg.payload.switchcmd = \"On\";\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":120,"wires":[["43f91110.6822c","1958d1bb.00e10e"]]},{"id":"c48bb42d.574338","type":"http in","z":"87dcf813.641a68","name":"test met get","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":130,"y":700,"wires":[["85560622.9da918","c766056b.e22bc8"]]},{"id":"b301bc18.86d74","type":"switch","z":"87dcf813.641a68","name":"check","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"cont","v":"idx","vt":"str"},{"t":"cont","v":"command","vt":"str"},{"t":"cont","v":"switchcmd","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":750,"y":760,"wires":[[],[],[],[]]},{"id":"1958d1bb.00e10e","type":"debug","z":"87dcf813.641a68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1210,"y":380,"wires":[]},{"id":"ae782a10.b76568","type":"comment","z":"87dcf813.641a68","name":"4, http get parameters","info":"http://192.168.20.32:1880/test?command=\"switchlight\"&idx=1005&switchcmd=\"On\"","x":160,"y":660,"wires":[]},{"id":"95a5498c.e52408","type":"http in","z":"87dcf813.641a68","name":"test met post","url":"/test2","method":"post","upload":false,"swaggerDoc":"","x":130,"y":460,"wires":[["85560622.9da918","c766056b.e22bc8"]]},{"id":"85560622.9da918","type":"http response","z":"87dcf813.641a68","name":"responce post","statusCode":"","headers":{"content-type":"application/json"},"x":220,"y":580,"wires":[]},{"id":"ba41611b.ddc5e","type":"comment","z":"87dcf813.641a68","name":"1. schakelaar zetten met inhoud in bericht","info":"werkt!","x":220,"y":60,"wires":[]},{"id":"514c29eb.afa658","type":"comment","z":"87dcf813.641a68","name":"3. http  post met json body","info":"werkt\nifttt activate gateway","x":170,"y":420,"wires":[]},{"id":"c766056b.e22bc8","type":"json","z":"87dcf813.641a68","name":"","property":"payload","action":"","pretty":false,"x":490,"y":460,"wires":[["2e0d0a88.102bf6"]]},{"id":"2e0d0a88.102bf6","type":"change","z":"87dcf813.641a68","name":"convert","rules":[{"t":"set","p":"command","pt":"msg","to":"payload.command","tot":"msg"},{"t":"set","p":"idx","pt":"msg","to":"payload.idx","tot":"msg"},{"t":"set","p":"switchcmd","pt":"msg","to":"payload.switchcmd","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":460,"wires":[["43f91110.6822c","1958d1bb.00e10e"]]},{"id":"8248a339.0a3cf","type":"inject","z":"87dcf813.641a68","name":"1005 uit","topic":"","payload":"{\"command\":\"switchlight\",\"idx\":1005,\"switchcmd\":\"On\"}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["1958d1bb.00e10e","c766056b.e22bc8"]]},{"id":"bc1bd210.b2c29","type":"comment","z":"87dcf813.641a68","name":"2. schakelaar met injector met inhoud","info":"werkt","x":210,"y":220,"wires":[]},{"id":"b47f58ae.8a7138","type":"mqtt-broker","z":"","name":"mqttdomoticz","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

I see only 1 flow, but I don't see the connection to the description of your flow.
What is not working ?

When i do a http://192.168.20.32:1880/test?command="switchlight"&idx=1005&switchcmd="On"
in the browser my switch does not go on.
The other scenarios in the flow by sending a http post via IFTT works great.
I also like to have the htttp get scenario (number 4) to work. Therefore the commandline vairiables have to be transformed to message.payload.idx etc.

Couple of things are incorrect:

Inject node sends a json as string, not as json.
The url you post is not correct. double "quotes" will not work
The json node converts between json strings and json.
The http nodes are used to create end-points (API stuff etc)

To do a simple request, you can use the http request node.

[{"id":"f5217538.897da8","type":"http request","z":"2fd5cad6.dafbf6","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","tls":"","proxy":"","authType":"basic","x":330,"y":820,"wires":[["374c51f1.766d4e"]]},{"id":"211ebf5c.d36538","type":"inject","z":"2fd5cad6.dafbf6","name":"request","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":820,"wires":[["f5217538.897da8"]]},{"id":"374c51f1.766d4e","type":"change","z":"2fd5cad6.dafbf6","name":"convert","rules":[{"t":"set","p":"command","pt":"msg","to":"payload.command","tot":"msg"},{"t":"set","p":"idx","pt":"msg","to":"payload.idx","tot":"msg"},{"t":"set","p":"switchcmd","pt":"msg","to":"payload.switchcmd","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":820,"wires":[["e52218f3.e6758"]]},{"id":"e52218f3.e6758","type":"debug","z":"2fd5cad6.dafbf6","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":670,"y":820,"wires":[]}]

Unless I am misunderstanding what the problem is.

THANK YOU BAKMAN, you helpt me a lot!

I think i am almost there. Reason why the light still isnt switched on is because of
idx value: "1005", this has to be 1005 (number) { command: "switchlight", idx: "1005", switchcmd: "On" }

So somewhere i have to convert this with something like tonumber?
@update: found it myself
msg.payload.idx = Number(msg.payload.idx); return msg;
return msg;

[{"id":"87dcf813.641a68","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b47f58ae.8a7138","type":"mqtt-broker","z":"","name":"mqttdomoticz","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"3bd55103.18210e","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"43f91110.6822c","type":"mqtt out","z":"87dcf813.641a68","name":"mqtt_domoticz/in","topic":"domoticz/in","qos":"0","retain":"false","broker":"b47f58ae.8a7138","x":1230,"y":120,"wires":[]},{"id":"5ce99120.422b4","type":"inject","z":"87dcf813.641a68","name":"1005 aan","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["9e0e34cb.7f1c08"]]},{"id":"9e0e34cb.7f1c08","type":"function","z":"87dcf813.641a68","name":"Maak boodschap 1005 wii en tv lamp Aan","func":"msg.payload = {};\nmsg.payload.command = \"switchlight\";\nmsg.payload.idx = 1005;\nmsg.payload.switchcmd = \"On\";\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":120,"wires":[["43f91110.6822c","1958d1bb.00e10e"]]},{"id":"c48bb42d.574338","type":"http in","z":"87dcf813.641a68","name":"test met get","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":130,"y":700,"wires":[["85560622.9da918","2e0d0a88.102bf6"]]},{"id":"b301bc18.86d74","type":"switch","z":"87dcf813.641a68","name":"check","property":"payload","propertyType":"msg","rules":[{"t":"nnull"},{"t":"cont","v":"idx","vt":"str"},{"t":"cont","v":"command","vt":"str"},{"t":"cont","v":"switchcmd","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":750,"y":760,"wires":[[],[],[],[]]},{"id":"1958d1bb.00e10e","type":"debug","z":"87dcf813.641a68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1210,"y":380,"wires":[]},{"id":"ae782a10.b76568","type":"comment","z":"87dcf813.641a68","name":"4, http get parameters","info":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","x":160,"y":660,"wires":[]},{"id":"95a5498c.e52408","type":"http in","z":"87dcf813.641a68","name":"test met post","url":"/test2","method":"post","upload":false,"swaggerDoc":"","x":130,"y":460,"wires":[["85560622.9da918","c766056b.e22bc8"]]},{"id":"85560622.9da918","type":"http response","z":"87dcf813.641a68","name":"responce post","statusCode":"","headers":{"content-type":"application/json"},"x":220,"y":580,"wires":[]},{"id":"ba41611b.ddc5e","type":"comment","z":"87dcf813.641a68","name":"1. schakelaar zetten met inhoud in bericht","info":"werkt!","x":220,"y":60,"wires":[]},{"id":"514c29eb.afa658","type":"comment","z":"87dcf813.641a68","name":"3. http  post met json body","info":"werkt\nifttt activate gateway","x":170,"y":420,"wires":[]},{"id":"c766056b.e22bc8","type":"json","z":"87dcf813.641a68","name":"","property":"payload","action":"","pretty":false,"x":490,"y":460,"wires":[["2e0d0a88.102bf6"]]},{"id":"2e0d0a88.102bf6","type":"change","z":"87dcf813.641a68","name":"convert","rules":[{"t":"set","p":"command","pt":"msg","to":"payload.command","tot":"msg"},{"t":"set","p":"idx","pt":"msg","to":"payload.idx","tot":"msg"},{"t":"set","p":"switchcmd","pt":"msg","to":"payload.switchcmd","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":460,"wires":[["43f91110.6822c","1958d1bb.00e10e"]]},{"id":"8248a339.0a3cf","type":"inject","z":"87dcf813.641a68","name":"1005 uit","topic":"","payload":"{\"command\":\"switchlight\",\"idx\":1005,\"switchcmd\":\"On\"}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["1958d1bb.00e10e","c766056b.e22bc8"]]},{"id":"bc1bd210.b2c29","type":"comment","z":"87dcf813.641a68","name":"2. schakelaar met injector met inhoud","info":"werkt","x":210,"y":220,"wires":[]},{"id":"64ac6cc7.0bd534","type":"http request","z":"87dcf813.641a68","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","tls":"","proxy":"","authType":"basic","x":410,"y":760,"wires":[["2e0d0a88.102bf6"]]},{"id":"586eba26.5678c4","type":"inject","z":"87dcf813.641a68","name":"request","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":760,"wires":[["64ac6cc7.0bd534"]]}]
1 Like

Number(n) works, I usually use parseInt(n) for integers or parseFloat(n) for floating point

ok, will change that too!
Last problem is that i use
\website:port\test for http post calls (see included flow comment nr 3)
and \website:port\test2 for http get calls. (see included flow comment nr 4)
both have their own way of creating a working mqtt message.
Is it possible to have only one \website:port\test (no ...\test2) and check in node-red if the call is a POST or GET ?

[{"id":"87dcf813.641a68","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b47f58ae.8a7138","type":"mqtt-broker","z":"","name":"mqttdomoticz","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"3bd55103.18210e","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"15","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"43f91110.6822c","type":"mqtt out","z":"87dcf813.641a68","name":"mqtt_domoticz/in","topic":"domoticz/in","qos":"0","retain":"false","broker":"b47f58ae.8a7138","x":1230,"y":120,"wires":[]},{"id":"5ce99120.422b4","type":"inject","z":"87dcf813.641a68","name":"1005 aan","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["9e0e34cb.7f1c08"]]},{"id":"9e0e34cb.7f1c08","type":"function","z":"87dcf813.641a68","name":"Maak boodschap 1005 wii en tv lamp Aan","func":"msg.payload = {};\nmsg.payload.command = \"switchlight\";\nmsg.payload.idx = 1005;\nmsg.payload.switchcmd = \"On\";\nreturn msg;","outputs":1,"noerr":0,"x":680,"y":120,"wires":[["43f91110.6822c","1958d1bb.00e10e"]]},{"id":"c48bb42d.574338","type":"http in","z":"87dcf813.641a68","name":"test met get","url":"/test","method":"get","upload":false,"swaggerDoc":"","x":130,"y":700,"wires":[["85560622.9da918","850fb7d7.ca39c8"]]},{"id":"1958d1bb.00e10e","type":"debug","z":"87dcf813.641a68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1290,"y":360,"wires":[]},{"id":"ae782a10.b76568","type":"comment","z":"87dcf813.641a68","name":"4, http get parameters","info":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","x":160,"y":660,"wires":[]},{"id":"95a5498c.e52408","type":"http in","z":"87dcf813.641a68","name":"test met post","url":"/test2","method":"post","upload":false,"swaggerDoc":"","x":130,"y":460,"wires":[["85560622.9da918","c766056b.e22bc8"]]},{"id":"85560622.9da918","type":"http response","z":"87dcf813.641a68","name":"responce post","statusCode":"","headers":{"content-type":"application/json"},"x":200,"y":580,"wires":[]},{"id":"ba41611b.ddc5e","type":"comment","z":"87dcf813.641a68","name":"1. schakelaar zetten met inhoud in bericht","info":"werkt!","x":220,"y":60,"wires":[]},{"id":"514c29eb.afa658","type":"comment","z":"87dcf813.641a68","name":"3. http  post met json body","info":"werkt\nifttt activate gateway","x":170,"y":420,"wires":[]},{"id":"c766056b.e22bc8","type":"json","z":"87dcf813.641a68","name":"","property":"payload","action":"","pretty":false,"x":490,"y":460,"wires":[["2e0d0a88.102bf6"]]},{"id":"2e0d0a88.102bf6","type":"change","z":"87dcf813.641a68","name":"convert","rules":[{"t":"set","p":"command","pt":"msg","to":"payload.command","tot":"msg"},{"t":"set","p":"idx","pt":"msg","to":"payload.idx","tot":"msg"},{"t":"set","p":"switchcmd","pt":"msg","to":"payload.switchcmd","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":800,"y":460,"wires":[["43f91110.6822c","1958d1bb.00e10e"]]},{"id":"8248a339.0a3cf","type":"inject","z":"87dcf813.641a68","name":"1005 uit","topic":"","payload":"{\"command\":\"switchlight\",\"idx\":1005,\"switchcmd\":\"Off\"}","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["1958d1bb.00e10e","c766056b.e22bc8"]]},{"id":"bc1bd210.b2c29","type":"comment","z":"87dcf813.641a68","name":"2. schakelaar met injector met inhoud","info":"werkt","x":210,"y":220,"wires":[]},{"id":"64ac6cc7.0bd534","type":"http request","z":"87dcf813.641a68","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","tls":"","proxy":"","authType":"basic","x":410,"y":760,"wires":[["850fb7d7.ca39c8"]]},{"id":"586eba26.5678c4","type":"inject","z":"87dcf813.641a68","name":"request","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":780,"wires":[["64ac6cc7.0bd534"]]},{"id":"850fb7d7.ca39c8","type":"function","z":"87dcf813.641a68","name":"convert idx","func":"msg.payload.idx = Number(msg.payload.idx); return msg;","outputs":1,"noerr":0,"x":610,"y":620,"wires":[["2e0d0a88.102bf6"]]},{"id":"ca1e623.681f6a","type":"http request","z":"87dcf813.641a68","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"http://192.168.20.32:1880/test?command=switchlight&idx=1005&switchcmd=On","tls":"","proxy":"","authType":"basic","x":350,"y":1240,"wires":[["2b015d9d.40e362"]]},{"id":"7b71161a.dbd048","type":"inject","z":"87dcf813.641a68","name":"request","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":1240,"wires":[["ca1e623.681f6a"]]},{"id":"2b015d9d.40e362","type":"debug","z":"87dcf813.641a68","name":"test","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"true","targetType":"full","x":710,"y":1240,"wires":[]}]

Also posted over here - Post or get check
(Don't reply here)