Forked Daapd - Node Red - Javasript function to read out object

Hello Guys/Girls,

I’m automating my home audio.
What I want is, if my movement sensor gets triggered, output to an airplay device.
So what I use is forked-daapd.
Forked Daapd has got an API, and with that I can ask if an airplay output device is selected.

This is the command to check properties for an airplay device:
curl -X GET "http://localhost:3689/api/outputs/57717330260976"
This command gets called via Exec function in Node Red.
Then I use the json to object converter.

so the output is an javascript object containing the following:
Bildschirmfoto 2020-09-27 um 19.22.07

Javascript:

var object = { id: "57717330260976", name: "Küche", type: "AirPlay", selected: true, has_password: false, requires_auth: false, needs_auth_key: false, volume: 20};

console.log(object.selected)

Output:
true

What I need is a function in javascript that just checks if selected is true or false and the outputs lets say, on or off. I need to use that in conjunction with further logical operations to selected that output.

I’m just a real noob in javascript :rofl:
The solution is easy for sure ^^
Thank you so much for you time and help in advance :slight_smile:

Let me know if you need any further information

[{"id":"472ee21c.db552c","type":"inject","z":"ffbd7f06.4a014","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":108,"y":1376,"wires":[["a25f9c60.da448"]]},{"id":"a25f9c60.da448","type":"http request","z":"ffbd7f06.4a014","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://localhost:3689/api/outputs/57717330260976","tls":"","persist":false,"proxy":"","authType":"","x":262,"y":1376,"wires":[["c9bcd41d.3d1418"]]},{"id":"c9bcd41d.3d1418","type":"switch","z":"ffbd7f06.4a014","name":"","property":"payload.selected","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":402,"y":1376,"wires":[["67fad707.4dc548"],["3a87002.5d965"]]},{"id":"67fad707.4dc548","type":"change","z":"ffbd7f06.4a014","name":"on","rules":[{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1376,"wires":[["6ed3a511.2aa23c"]]},{"id":"3a87002.5d965","type":"change","z":"ffbd7f06.4a014","name":"off","rules":[{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":1424,"wires":[["6ed3a511.2aa23c"]]},{"id":"6ed3a511.2aa23c","type":"debug","z":"ffbd7f06.4a014","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":684,"y":1376,"wires":[]}]

image

[{"id":"cc163bcb.23a6b8","type":"inject","z":"ffbd7f06.4a014","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":108,"y":1504,"wires":[["f23ec0a6.1cfd2"]]},{"id":"f23ec0a6.1cfd2","type":"http request","z":"ffbd7f06.4a014","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"http://localhost:3689/api/outputs/57717330260976","tls":"","persist":false,"proxy":"","authType":"","x":262,"y":1504,"wires":[["23203123.65368e"]]},{"id":"f4e9717b.03242","type":"debug","z":"ffbd7f06.4a014","name":"do stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":556,"y":1504,"wires":[]},{"id":"23203123.65368e","type":"function","z":"ffbd7f06.4a014","name":"","func":"msg.payload = msg.payload.selected ? 'on' : 'off';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":412,"y":1504,"wires":[["f4e9717b.03242"]]}]

@Kermit thank you very much. Your answer got me exactly what I needed. Much appreciated !! :slight_smile: