Read original value, do some stuff, write old value

hello,

i'm a new node-red user maybe it is not so complicated for others but i can't find a solution.

i have mpd running, now i want to play a message(not with mpd) over this soundcard but the message is not so loud.
that means before i can play the message i must look if mpd state is "play or stop" and read the original volume.
now i can set the new volume to "75%" play the message and after that set original volume + if its played before set mpd state to play.

how can i solve this?

[{"id":"c6b54c54.0c1e7","type":"tab","label":"Flow 4","disabled":false,"info":""},{"id":"54fafb8c.7afc44","type":"http request","z":"c6b54c54.0c1e7","name":"call Jarvis REST API HTTP","method":"POST","ret":"obj","paytoqs":false,"url":"http://192.168.178.129:8080","tls":"","persist":false,"proxy":"","authType":"","x":1060,"y":480,"wires":[[]]},{"id":"dccd6a6d.f66b28","type":"mpd out","z":"c6b54c54.0c1e7","name":"Jarvis mpd out","topic":"","server":"6aace7b0.9d3d08","x":820,"y":200,"wires":[["8c1893ed.16655"]]},{"id":"a21fb832.0c2638","type":"change","z":"c6b54c54.0c1e7","name":"topic req_status","rules":[{"t":"set","p":"topic","pt":"msg","to":"req_status","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":260,"wires":[["c63be68b.bb0868"]]},{"id":"d8562838.c069b8","type":"function","z":"c6b54c54.0c1e7","name":"status mpd","func":"msg.payload=\"status\"\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":200,"wires":[["dccd6a6d.f66b28","a21fb832.0c2638"]]},{"id":"8c1893ed.16655","type":"change","z":"c6b54c54.0c1e7","name":"topic status_mpd","rules":[{"t":"set","p":"topic","pt":"msg","to":"status_mpd","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1010,"y":200,"wires":[["c63be68b.bb0868"]]},{"id":"fe396b8.4a2b298","type":"debug","z":"c6b54c54.0c1e7","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"mpd_state","targetType":"msg","x":1060,"y":320,"wires":[]},{"id":"c63be68b.bb0868","type":"function","z":"c6b54c54.0c1e7","name":"wait for old state","func":"var req_In_Topics = [\"req_status\",\"status_mpd\"];\nvar allOK = true;\n\nreq_In_Topics.forEach(function(array_value) {\n    if (msg.topic == array_value) {\n        context.set(\"context_\" + array_value, msg.payload);\n    }\n})\n\n// do we have a full set of inputs?\nreq_In_Topics.forEach(function(array_value) {\n    if (typeof context.get(\"context_\" + array_value) === 'undefined') {\n        allOK = false;\n    }\n})\n\nif(allOK){\n    // we have values for all the topics so go ahead and do whatever \n    // is necessary fetching the values using context.get(\"context_??topic??\") etc\n    old_state = context.get(\"context_status_mpd\");\n    msg.topic = \"old_state\";\n    msg.payload = {\n        \"old_vol\": old_state[0].volume,\n        \"old_state\": old_state[0].state\n    };    \n\n\n    // reset Context for next cycle\n    req_In_Topics.forEach(function(array_value) {\n            context.set(\"context_\" + array_value, undefined);\n    })\n}else{\n    msg = null;\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"x":1200,"y":220,"wires":[["5eb1752f.74121c"]]},{"id":"5eb1752f.74121c","type":"function","z":"c6b54c54.0c1e7","name":"wait for all input","func":"var req_In_Topics = [\"payload_jarvis\",\"old_state\"];\nvar allOK = true;\n\nreq_In_Topics.forEach(function(array_value) {\n    if (msg.topic == array_value) {\n        context.set(\"context_\" + array_value, msg.payload);\n    }\n})\n\n// do we have a full set of inputs?\nreq_In_Topics.forEach(function(array_value) {\n    if (typeof context.get(\"context_\" + array_value) === 'undefined') {\n        allOK = false;\n    }\n})\n\nif(allOK){\n    // we have values for all the topics so go ahead and do whatever \n    // is necessary fetching the values using context.get(\"context_??topic??\") etc\n    msg.mpd_state = context.get(\"context_old_state\");\n    msg.payload = context.get(\"context_payload_jarvis\");\n    // reset Context for next cycle\n    req_In_Topics.forEach(function(array_value) {\n            context.set(\"context_\" + array_value, undefined);\n    })\n}else{\n    msg = null;\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"x":840,"y":360,"wires":[["fe396b8.4a2b298","16f8b02b.fbde3"]]},{"id":"16f8b02b.fbde3","type":"debug","z":"c6b54c54.0c1e7","name":"","active":true,"console":"false","complete":"false","x":1050,"y":360,"wires":[]},{"id":"c92ded3c.0da4d","type":"function","z":"c6b54c54.0c1e7","name":"create payload for tts","func":"msg.payload = {\n    \"key\": \"secretjarvis\",\n    \"say\": \"Hello World\"\n};\n\nreturn msg;","outputs":1,"noerr":0,"x":340,"y":360,"wires":[["9facfee3.fbd7f"]]},{"id":"a6e91a7c.9802d8","type":"inject","z":"c6b54c54.0c1e7","name":"Trigger","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":200,"wires":[["d8562838.c069b8","c92ded3c.0da4d"]]},{"id":"9facfee3.fbd7f","type":"change","z":"c6b54c54.0c1e7","name":"topic payload_jarvis","rules":[{"t":"set","p":"topic","pt":"msg","to":"payload_jarvis","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":360,"wires":[["5eb1752f.74121c"]]},{"id":"3ecdf341.3be55c","type":"comment","z":"c6b54c54.0c1e7","name":"now stop mpd","info":"","x":1010,"y":400,"wires":[]},{"id":"454e8e09.57a1d","type":"comment","z":"c6b54c54.0c1e7","name":"now set volume to 75%","info":"","x":1040,"y":440,"wires":[]},{"id":"932af7c7.a43648","type":"comment","z":"c6b54c54.0c1e7","name":"now do this","info":"","x":850,"y":480,"wires":[]},{"id":"aacd3804.3a30d8","type":"comment","z":"c6b54c54.0c1e7","name":"set volume back to original","info":"","x":1050,"y":520,"wires":[]},{"id":"fcec9559.4b4008","type":"comment","z":"c6b54c54.0c1e7","name":"if mpd state is play before set state play","info":"","x":1090,"y":560,"wires":[]},{"id":"37ffeb7b.b84134","type":"comment","z":"c6b54c54.0c1e7","name":"request status mpd","info":"","x":570,"y":160,"wires":[]},{"id":"6aace7b0.9d3d08","type":"mpd-server","z":"","host":"192.168.178.129","port":"6600"}]

have you tried adding the original volume to the msg? call it msg.original_volume, then you coud use that value to reset it...that is if the mpd-out node doesn't create a brand new msg.

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