Read json and extract id from it

Hi, i need some help!
and I want to select the idx where name equal as the name received by a post (msg.name)
Is that possible?

In node red i send a json query to my domoticz
i execute http://192.168.20.35:82/json.htm?type=command&param=getlightswitches
and i get the following output:
I need an idx for a specifica switch name received by a post, for example 'Lantaarn' and need the idx of it. next step will be to turn idx xxx on (that part already works)

{
"result" : [
{
"DimmerLevels" : "none",
"IsDimmer" : false,
"Name" : "voice_vorstalarm",
"SubType" : "Switch",
"Type" : "Light/Switch",
"idx" : "1163"
},
{
"DimmerLevels" : "none",
"IsDimmer" : false,
"Name" : "voice_wasmachine",
"SubType" : "Switch",
"Type" : "Light/Switch",
"idx" : "1149"
},
{
"DimmerLevels" : "none",
"IsDimmer" : false,
"Name" : "voordeurbel",
"SubType" : "Switch",
"Type" : "Light/Switch",
"idx" : "1182"
},
{
"DimmerLevels" : "none",
"IsDimmer" : false,
"Name" : "vriezer",
"SubType" : "Switch",
"Type" : "Light/Switch",
"idx" : "469"
},
{
"DimmerLevels" : "none",
"IsDimmer" : false,
"Name" : "wasmachine",
"SubType" : "Switch",
"Type" : "Light/Switch",
"idx" : "976"
},
{
"DimmerLevels" : "none",
"IsDimmer" : false,
"Name" : "wii_lan_ip",
"SubType" : "AC",
"Type" : "Lighting 2",
"idx" : "288"
}
],
"status" : "OK",
"title" : "GetLightSwitches"
}

as msg.payload.result is an array of objects, you could use Array.find() prototype.

Here is an example...

[{"id":"ff8f07f0.a4d518","type":"inject","z":"ade1a96c.062848","name":"Emulate data source","topic":"","payload":"{ \"result\" : [ { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"voice_vorstalarm\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"1163\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"voice_wasmachine\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"1149\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"voordeurbel\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"1182\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"vriezer\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"469\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"wasmachine\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"976\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"wii_lan_ip\", \"SubType\" : \"AC\", \"Type\" : \"Lighting 2\", \"idx\" : \"288\" } ], \"status\" : \"OK\", \"title\" : \"GetLightSwitches\" }","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":762,"y":120,"wires":[["eb5252e1.cb8a1"]]},{"id":"e4e6698a.662c58","type":"debug","z":"ade1a96c.062848","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1226,"y":168,"wires":[]},{"id":"9b19d12b.8b225","type":"function","z":"ade1a96c.062848","name":"find","func":"let arr = msg.payload.result;\nlet find = msg.find;\nlet found = arr.find(function(o,i){\n    return o.Name == find\n})\nif(found){\n    msg.payload = found\n    return [msg,null];\n}\n\nnode.warn(`could not find '${msg.find}'`);","outputs":1,"noerr":0,"x":1202,"y":120,"wires":[["e4e6698a.662c58"]]},{"id":"eb5252e1.cb8a1","type":"change","z":"ade1a96c.062848","name":"find voice_vorstalarm","rules":[{"t":"set","p":"find","pt":"msg","to":"voice_vorstalarm","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":988,"y":120,"wires":[["9b19d12b.8b225"]]},{"id":"be97cb5b.1448d8","type":"inject","z":"ade1a96c.062848","name":"Emulate data source","topic":"","payload":"{ \"result\" : [ { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"voice_vorstalarm\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"1163\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"voice_wasmachine\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"1149\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"voordeurbel\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"1182\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"vriezer\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"469\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"wasmachine\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"976\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"wii_lan_ip\", \"SubType\" : \"AC\", \"Type\" : \"Lighting 2\", \"idx\" : \"288\" } ], \"status\" : \"OK\", \"title\" : \"GetLightSwitches\" }","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":762,"y":72,"wires":[["b296fea1.9a217"]]},{"id":"b296fea1.9a217","type":"change","z":"ade1a96c.062848","name":"find Lantaarn","rules":[{"t":"set","p":"find","pt":"msg","to":"Lantaarn","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":958,"y":72,"wires":[["9b19d12b.8b225"]]},{"id":"e2330b3e.b54a18","type":"inject","z":"ade1a96c.062848","name":"Emulate data source","topic":"","payload":"{ \"result\" : [ { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"voice_vorstalarm\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"1163\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"voice_wasmachine\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"1149\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"voordeurbel\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"1182\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"vriezer\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"469\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"wasmachine\", \"SubType\" : \"Switch\", \"Type\" : \"Light/Switch\", \"idx\" : \"976\" }, { \"DimmerLevels\" : \"none\", \"IsDimmer\" : false, \"Name\" : \"wii_lan_ip\", \"SubType\" : \"AC\", \"Type\" : \"Lighting 2\", \"idx\" : \"288\" } ], \"status\" : \"OK\", \"title\" : \"GetLightSwitches\" }","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":762,"y":168,"wires":[["24406a14.15c486"]]},{"id":"24406a14.15c486","type":"change","z":"ade1a96c.062848","name":"find voordeurbel","rules":[{"t":"set","p":"find","pt":"msg","to":"voordeurbel","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":968,"y":168,"wires":[["9b19d12b.8b225"]]}]

Thanks, After weaks of trying finaly a beginning !

I still need some help:

  1. in find emulate name i need the value of name from the data source of from the post
  2. i think i loose some info because my switch does not fires. my mqtt works ok

[{"id":"ce203651.101258","type":"tab","label":"Domoticz WatchDog","disabled":false,"info":""},{"id":"ea662623.d14a98","type":"http request","z":"ce203651.101258","name":"test return","method":"GET","ret":"obj","paytoqs":false,"url":"http://192.168.20.35:82/json.htm?type=command&param=getlightswitches","tls":"","proxy":"","x":380,"y":120,"wires":[["374e028a.06636e"]]},{"id":"d59c0ea7.99a59","type":"debug","z":"ce203651.101258","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1230,"y":60,"wires":[]},{"id":"b65848b2.bcd588","type":"function","z":"ce203651.101258","name":"find","func":"let arr = msg.payload.result;\nlet find = msg.find;\nlet found = arr.find(function(o,i){\n return o.Name == find\n})\nif(found){\n msg.payload = found\n return [msg,null];\n}\n\nnode.warn(Switch met opgegeven naam niet gevonden '${msg.find}');","outputs":1,"noerr":0,"x":350,"y":420,"wires":[["994f245.4f6e2d8"]]},{"id":"374e028a.06636e","type":"change","z":"ce203651.101258","name":"find emulate name","rules":[{"t":"set","p":"find","pt":"msg","to":"lantaarn","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":120,"wires":[["b65848b2.bcd588"]]},{"id":"994f245.4f6e2d8","type":"change","z":"ce203651.101258","name":"maak switch bericht","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"},{"t":"set","p":"level","pt":"msg","to":"payload.level","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":420,"wires":[["20d4d014.de57c","d59c0ea7.99a59"]]},{"id":"20d4d014.de57c","type":"mqtt out","z":"ce203651.101258","name":"","topic":"domoticz/in","qos":"","retain":"","broker":"21fd69bf.668b46","x":1130,"y":420,"wires":},{"id":"2139ca6d.abdcc6","type":"comment","z":"ce203651.101258","name":"This is the payload i get from IFTT webhook POST BODY","info":"","x":230,"y":60,"wires":},{"id":"854061ae.dd1ea","type":"comment","z":"ce203651.101258","name":"domotica only switch idx to on does not now name","info":"","x":770,"y":340,"wires":},{"id":"ddf8783b.ecde78","type":"http in","z":"ce203651.101258","name":"LIVE met post","url":"/pvkapi2","method":"post","upload":false,"swaggerDoc":"","x":130,"y":120,"wires":[["ea662623.d14a98"]]},{"id":"9abdda3a.34b798","type":"comment","z":"ce203651.101258","name":"body content","info":"{"command":"switchlight","name":"lantaarn","switchcmd":"On"}","x":530,"y":60,"wires":},{"id":"3a61696f.685806","type":"inject","z":"ce203651.101258","name":"Emulate data source","topic":"","payload":"{"command":"switchlight","name":"lantaarn","switchcmd":"On"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":200,"wires":[["ea662623.d14a98"]]},{"id":"21fd69bf.668b46","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":""}]