Keep track of volume number in NR / HA

For watching tv, I send IR codes to my dumb amplifier to:
turn the volume down x3 when changing to tv input
turn it down x4 when changing to HD (louder) channels (turns input boolean on in Home Assistant)
turn it up x4 when changing to non-HD (quieter) channels (turns off input boolean in Home Assistant)
turn the volume up x4 when changing to non-tv input
The starting volume number is always 40 (on the amp).
What happens is that if the IR code sent to change the channel messes up, NR registers HD channel and sends V- x4 even though I got 1 instead of 101 and so I can end up on a quiet channel with quiet volume. I think two quiet channels in a row would add x8 total volume at present as well.
I can see that I need to save the volume of 40 as a starting variable (global?) and have NR reference that number before subtracting or adding to it, depending on channel selected, then have it return to 40 upon exit but I still am new to NR and have a minimal understanding of function nodes. I am good at adapting others code and that's how I prefer to learn, I am Dyslexic so please don't just post links to un-fathomable articles for me to read - I've already googled around and that's why I'm here!
Here's the work in progress...

[{"id":"8e47f60c.78c718","type":"subflow","name":"Philips SOURCE (TV to HDMI2)","info":"","category":"","in":[{"x":20,"y":80,"wires":[{"id":"5dce09ca.95b638"}]}],"out":[],"env":[],"color":"#DDAA99"},{"id":"5dce09ca.95b638","type":"api-call-service","z":"8e47f60c.78c718","name":"TV Philips SOURCE","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"broadlink","service":"send","entityId":"","data":"{\"packet\":[\"JgBYAFceDh0ODw4PEBwdDg4QDg8ODw4PDg8PDg4PDg8ODxwPDg8OHQ4PDg8OAArDVx4OHg4PDw4OHhwPDg8ODw4PDg8ODw4PDg8ODw4PHg4ODw4dDg8ODxAADQU=\"],\"host\":\"192.168.1.134\"}","dataType":"json","mergecontext":"","output_location":"1","output_location_type":"flow","mustacheAltTags":false,"x":200,"y":74,"wires":[["91bb4894.40e508"]]},{"id":"d4d31203.7e99","type":"api-call-service","z":"8e47f60c.78c718","name":"TV Philips RIGHT","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"broadlink","service":"send","entityId":"","data":"{\"packet\":[\"JgBQAFceDh0ODw8ODh4eDQ8PDg8ODw4ODw8ODhAODg8cHR4ODh0eDg4ACtFXHg8dDw4ODw4eHQ4ODw8ODw4PDg4PDw0PDw4PHR0cDw4eHA8PAA0FAAAAAAAAAAA=\"],\"host\":\"192.168.1.134\"}","dataType":"json","mergecontext":"","output_location":"1","output_location_type":"flow","mustacheAltTags":false,"x":203,"y":143,"wires":[["52ffdfd3.d82f9"]]},{"id":"1c5694df.b8f5ab","type":"api-call-service","z":"8e47f60c.78c718","name":"TV Philips OK","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"broadlink","service":"send","entityId":"","data":"{\"packet\":[\"JgBQAFceDh0PDg8OKy0ODw8ODg8ODw4ODw4PDg4PHR0dDw4PDh0ODw4ACsNXHg4dDw4ODystDw4ODw4PDg4PDg4PDg8ODx0dHQ8ODw4dDg8OAA0FAAAAAAAAAAA=\"],\"host\":\"192.168.1.134\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":205,"y":434,"wires":[[]]},{"id":"3b1126de.bb69ba","type":"api-call-service","z":"8e47f60c.78c718","name":"TV Philips RIGHT","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"broadlink","service":"send","entityId":"","data":"{\"packet\":[\"JgBQAFceDh0ODw8ODh4eDQ8PDg8ODw4ODw8ODhAODg8cHR4ODh0eDg4ACtFXHg8dDw4ODw4eHQ4ODw8ODw4PDg4PDw0PDw4PHR0cDw4eHA8PAA0FAAAAAAAAAAA=\"],\"host\":\"192.168.1.134\"}","dataType":"json","mergecontext":"","output_location":"1","output_location_type":"flow","mustacheAltTags":false,"x":206,"y":211,"wires":[["f2cacbab.1a0268"]]},{"id":"ae07ff4d.45a43","type":"api-call-service","z":"8e47f60c.78c718","name":"TV Philips RIGHT","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"broadlink","service":"send","entityId":"","data":"{\"packet\":[\"JgBQAFceDh0ODw8ODh4eDQ8PDg8ODw4ODw8ODhAODg8cHR4ODh0eDg4ACtFXHg8dDw4ODw4eHQ4ODw8ODw4PDg4PDw0PDw4PHR0cDw4eHA8PAA0FAAAAAAAAAAA=\"],\"host\":\"192.168.1.134\"}","dataType":"json","mergecontext":"","output_location":"1","output_location_type":"flow","mustacheAltTags":false,"x":206,"y":281,"wires":[["2238d5c3.d344aa"]]},{"id":"91bb4894.40e508","type":"delay","z":"8e47f60c.78c718","name":"","pauseType":"delay","timeout":"400","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":202,"y":109,"wires":[["d4d31203.7e99"]]},{"id":"52ffdfd3.d82f9","type":"delay","z":"8e47f60c.78c718","name":"","pauseType":"delay","timeout":"300","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":206,"y":177,"wires":[["3b1126de.bb69ba"]]},{"id":"f2cacbab.1a0268","type":"delay","z":"8e47f60c.78c718","name":"","pauseType":"delay","timeout":"300","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":206,"y":244,"wires":[["ae07ff4d.45a43"]]},{"id":"c32456a0.d5b9e8","type":"delay","z":"8e47f60c.78c718","name":"","pauseType":"delay","timeout":"400","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":215,"y":397,"wires":[["1c5694df.b8f5ab"]]},{"id":"ca841c86.9287a","type":"api-call-service","z":"8e47f60c.78c718","name":"TV Philips RIGHT","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"broadlink","service":"send","entityId":"","data":"{\"packet\":[\"JgBQAFceDh0ODw8ODh4eDQ8PDg8ODw4ODw8ODhAODg8cHR4ODh0eDg4ACtFXHg8dDw4ODw4eHQ4ODw8ODw4PDg4PDw0PDw4PHR0cDw4eHA8PAA0FAAAAAAAAAAA=\"],\"host\":\"192.168.1.134\"}","dataType":"json","mergecontext":"","output_location":"1","output_location_type":"flow","mustacheAltTags":false,"x":206,"y":359,"wires":[["c32456a0.d5b9e8"]]},{"id":"2238d5c3.d344aa","type":"delay","z":"8e47f60c.78c718","name":"","pauseType":"delay","timeout":"300","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":206,"y":321,"wires":[["ca841c86.9287a"]]},{"id":"4c0fa585.a0934c","type":"api-current-state","z":"f02bb21f.0c99b","name":"Philips TV On?","server":"78ebbc5c.49dca4","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.tv_philips","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":780,"y":2560,"wires":[["7398897a.6b1ba8"],["8378117e.3b2b9"]]},{"id":"8378117e.3b2b9","type":"api-call-service","z":"f02bb21f.0c99b","name":"TV Philips ON","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"turn_on","entityId":"media_player.tv_philips","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1000,"y":2600,"wires":[["964e1cec.84795"]]},{"id":"7398897a.6b1ba8","type":"api-call-service","z":"f02bb21f.0c99b","name":"TV Philips to TV input","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"broadlink","service":"send","entityId":"","data":"{\"packet\" : [\"JgBQAFkcDh0ODw4PKy0ODw4PDg8ODg8MEQ8ODh0dDg8dDw4PDg4PDw4ACtJXHg4dDg4PDyssDg8ODw4PDg8ODw4PDg8eHBANHg0QDRANEAsSAA0FAAAAAAAAAAA=\"], \"host\": \"192.168.1.134\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1020,"y":2540,"wires":[["5f98db93.0a92f4"]]},{"id":"ab7c20b7.8e059","type":"link in","z":"f02bb21f.0c99b","name":"The Lounge TV","links":["bf1b62b8.33d9f"],"x":295,"y":2580,"wires":[["4bf559ce.a86f08"]]},{"id":"b1debed2.c317c","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V+","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_up","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1220,"y":2660,"wires":[["b8263945.512e78"]]},{"id":"b8263945.512e78","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V+","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_up","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1220,"y":2680,"wires":[["1529043a.8de5ec"]]},{"id":"1529043a.8de5ec","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V+","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_up","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1220,"y":2700,"wires":[["c1bec541.2cdcf8"]]},{"id":"4bf559ce.a86f08","type":"switch","z":"f02bb21f.0c99b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"else"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":590,"y":2580,"wires":[["4c0fa585.a0934c"],[],["b4ff91d8.e999e"]]},{"id":"81ca20c0.9f621","type":"subflow:8e47f60c.78c718","z":"f02bb21f.0c99b","name":"","x":1230,"y":2760,"wires":[]},{"id":"d97ad1cb.f9b9","type":"api-call-service","z":"f02bb21f.0c99b","name":"TV Philips Off","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"turn_off","entityId":"media_player.tv_philips","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1180,"y":2800,"wires":[["e707b52a.2fa368"]]},{"id":"b4ff91d8.e999e","type":"api-current-state","z":"f02bb21f.0c99b","name":"PC On?","server":"78ebbc5c.49dca4","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.my_computer_connected","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1000,"y":2660,"wires":[["81ca20c0.9f621","b1debed2.c317c"],["d97ad1cb.f9b9","81ca20c0.9f621"]]},{"id":"3f70eea6.abbfc2","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo Amp On (DVD)","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"select_source","entityId":"media_player.amp_onkyo","data":"{\"source\":\"DVD\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":2540,"y":2700,"wires":[[]]},{"id":"efed9ec8.d55b5","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo DVD","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"select_source","entityId":"media_player.amp_onkyo","data":"{\"source\":\"CBL/SAT\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2510,"y":2800,"wires":[[]]},{"id":"297651f4.ad1d7e","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo CBL/SAT","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"select_source","entityId":"media_player.amp_onkyo","data":"{\"source\":\"CBL/SAT\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2520,"y":2640,"wires":[[]]},{"id":"bfdbd4f2.c11538","type":"link in","z":"f02bb21f.0c99b","name":"","links":["b62e65f7.d04308","c5617d82.1d045","36f5ea2b.195fe6","b9200c33.3b439","7ad91a35.dee6a4","8dce91fe.b0e55","560a061e.260c48","beb9df6.253ac2","a9deab21.30d168","d6151d9b.364ad","8f05e26d.45334"],"x":295,"y":2520,"wires":[["88e2cdf9.de5f4","4bf559ce.a86f08"]]},{"id":"5f98db93.0a92f4","type":"trigger","z":"f02bb21f.0c99b","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":1200,"y":2540,"wires":[["5b8d880b.ebb968"]]},{"id":"964e1cec.84795","type":"trigger","z":"f02bb21f.0c99b","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":1200,"y":2600,"wires":[["5b8d880b.ebb968"]]},{"id":"e15a3a51.37d988","type":"trigger","z":"f02bb21f.0c99b","op1":"","op2":"off","op1type":"nul","op2type":"str","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":2360,"y":2700,"wires":[["3f70eea6.abbfc2"]]},{"id":"9356e3c8.f2a6a","type":"trigger","z":"f02bb21f.0c99b","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":2360,"y":2640,"wires":[["297651f4.ad1d7e"]]},{"id":"e707b52a.2fa368","type":"trigger","z":"f02bb21f.0c99b","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":1360,"y":2800,"wires":[["efed9ec8.d55b5"]]},{"id":"88e2cdf9.de5f4","type":"trigger","z":"f02bb21f.0c99b","op1":"","op2":"on","op1type":"nul","op2type":"str","duration":"15","extend":false,"units":"s","reset":"","bytopic":"all","name":"15s","x":430,"y":2500,"wires":[["18922dd.d7528d2"]]},{"id":"18922dd.d7528d2","type":"link out","z":"f02bb21f.0c99b","name":"After Amp","links":["446870c2.20d66","632514f6.65537c","96af87c1.ae76c8","d955f9ed.db75e8","808eb58.00a9b48","d57ab0a1.a396e","a7797048.6b954","6cd1a181.19634","5c8d3c86.cb1044","6f7abfcc.563c9","ec66b818.46c488"],"x":535,"y":2520,"wires":[]},{"id":"77be71d.191d29","type":"switch","z":"f02bb21f.0c99b","name":"HD True = 1 to 10 Else 11","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"B.B.C One","vt":"str"},{"t":"eq","v":"B.B.C Two","vt":"str"},{"t":"eq","v":"I.T.V One","vt":"str"},{"t":"eq","v":"Channel Four","vt":"str"},{"t":"eq","v":"B.B.C Three","vt":"str"},{"t":"eq","v":"B.B.C Four","vt":"str"},{"t":"eq","v":"B.B.C News","vt":"str"},{"t":"eq","v":"Al Jazeera","vt":"str"},{"t":"eq","v":"Channel Four Plus One","vt":"str"},{"t":"eq","v":"Four Seven","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":11,"x":1610,"y":2580,"wires":[["8a21b51a.1cc588"],["8a21b51a.1cc588"],["8a21b51a.1cc588"],["8a21b51a.1cc588"],["8a21b51a.1cc588"],["8a21b51a.1cc588"],["8a21b51a.1cc588"],["8a21b51a.1cc588"],["8a21b51a.1cc588"],["8a21b51a.1cc588"],["4fad7f86.9f289"]]},{"id":"8a21b51a.1cc588","type":"api-current-state","z":"f02bb21f.0c99b","name":"HD Channel V-","server":"78ebbc5c.49dca4","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.tv_channel_audio","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1920,"y":2520,"wires":[["67824c99.331554"],[]]},{"id":"4fad7f86.9f289","type":"api-current-state","z":"f02bb21f.0c99b","name":"HD Channel V+","server":"78ebbc5c.49dca4","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.tv_channel_audio","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1920,"y":2640,"wires":[["64bf4dd.45d59b4"],[]]},{"id":"70c44d6b.2105f4","type":"api-call-service","z":"f02bb21f.0c99b","name":"on","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.tv_channel_audio","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":2210,"y":2520,"wires":[["9356e3c8.f2a6a"]]},{"id":"a77ffb30.862ce8","type":"api-call-service","z":"f02bb21f.0c99b","name":"off","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.tv_channel_audio","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":2210,"y":2640,"wires":[["9356e3c8.f2a6a"]]},{"id":"c81fba3f.80af68","type":"server-state-changed","z":"f02bb21f.0c99b","name":"Audio Boolean","server":"78ebbc5c.49dca4","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.tv_channel_audio","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":380,"y":2800,"wires":[["d219137b.20b2d"]]},{"id":"d219137b.20b2d","type":"switch","z":"f02bb21f.0c99b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":580,"y":2800,"wires":[["3c3ac8dc.825d98"],["be01bba.8da2848"]]},{"id":"6a66d8e1.569248","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V-","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_down","entityId":"","data":"{\"entity_id\":\" media_player.amp_onkyo\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":910,"y":2760,"wires":[["b74a3a1e.b41108"]]},{"id":"b74a3a1e.b41108","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V-","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_down","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":910,"y":2780,"wires":[["60668b7b.33a7e4"]]},{"id":"60668b7b.33a7e4","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V-","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_down","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":910,"y":2800,"wires":[[]]},{"id":"be01bba.8da2848","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V+","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_up","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":910,"y":2900,"wires":[["33f160b1.bb9a"]]},{"id":"33f160b1.bb9a","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V+","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_up","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":910,"y":2920,"wires":[["6214ccb4.a942a4"]]},{"id":"6214ccb4.a942a4","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V+","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_up","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":910,"y":2940,"wires":[[]]},{"id":"3c3ac8dc.825d98","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V-","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_down","entityId":"","data":"{\"entity_id\":\" media_player.amp_onkyo\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":910,"y":2740,"wires":[["6a66d8e1.569248"]]},{"id":"5b8d880b.ebb968","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V-","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_down","entityId":"","data":"{\"entity_id\":\" media_player.amp_onkyo\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1380,"y":2560,"wires":[["794eaa3e.7a6394"]]},{"id":"794eaa3e.7a6394","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V-","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_down","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1380,"y":2580,"wires":[["24208e0e.a359f2"]]},{"id":"24208e0e.a359f2","type":"api-call-service","z":"f02bb21f.0c99b","name":"Onkyo V-","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_down","entityId":"media_player.amp_onkyo","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1380,"y":2600,"wires":[["77be71d.191d29"]]},{"id":"67824c99.331554","type":"change","z":"f02bb21f.0c99b","name":"off to on","rules":[{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2080,"y":2520,"wires":[["70c44d6b.2105f4"]]},{"id":"64bf4dd.45d59b4","type":"change","z":"f02bb21f.0c99b","name":"on to off","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2080,"y":2640,"wires":[["a77ffb30.862ce8"]]},{"id":"c1bec541.2cdcf8","type":"api-call-service","z":"f02bb21f.0c99b","name":"off","server":"78ebbc5c.49dca4","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.tv_channel_audio","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":2210,"y":2700,"wires":[["e15a3a51.37d988"]]},{"id":"78ebbc5c.49dca4","type":"server","z":"","name":"My Home Assistant","legacy":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

The bit I didn't include is the channel selection and Alexa nodes. Thanks

Sorry to hear that but you do the same to us with your flow :wink:
Please export your flow again, read this post and edit your post.

Thanks @bakman2 :roll_eyes:, I had followed that post but it only added one back tick front and back, not three. I had to add the back ticks manually. Running Chrome on Win10 with UK English keyboard. Hope that's got it.

edit: Ah! 'own line' was what I missed!

An update, as anyone reading this will be learning as well - I've played around with the Globals and Functions (thanks Steve!) and can now set the Global count number to 40, then add or subtract x4. I can work out how to tie that in with the volume control from there.
Just wondered why only one (of the three) Global function nodes shows the number '40'? I would have thought it would be mirrored across all of them.

[{"id":"ddc1a179.1d721","type":"inject","z":"f5d634f3.9e4378","name":"","topic":"sensors/sensor1","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"x":150,"y":1980,"wires":[["3e751bc7.00ceb4"]]},{"id":"3e751bc7.00ceb4","type":"function","z":"f5d634f3.9e4378","name":"Sets Global to 40","func":"\nvar count=flow.get('count') || 40;\nvar gcount=global.get('count') || 0;\n\ncount +=4;\nmsg.payload=\"F10 \"+\" flow= \"+count+ \"  global= \"+gcount;\nflow.set('count',count);\nglobal.set('count',gcount);\nreturn msg;","outputs":1,"noerr":0,"x":319,"y":1887,"wires":[["94c38aef.59bf78"]]},{"id":"94c38aef.59bf78","type":"debug","z":"f5d634f3.9e4378","name":"","active":true,"console":"false","complete":"false","x":462,"y":1968,"wires":[]},{"id":"bb64ec27.bbcb8","type":"inject","z":"f5d634f3.9e4378","name":"","topic":"sensors/sensor1","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"x":690,"y":1980,"wires":[["1a5e8112.0dca0f"]]},{"id":"1a5e8112.0dca0f","type":"function","z":"f5d634f3.9e4378","name":"Global +4","func":"\nvar count=flow.get('count') || 0;\nvar gcount=global.get('count') || 0;\n\ncount +=4;\nmsg.payload=\"F10 \"+\" flow= \"+count+ \"  global= \"+gcount;\nflow.set('count',count);\nglobal.set('count',gcount);\nreturn msg;","outputs":1,"noerr":0,"x":829,"y":1887,"wires":[["e4f1ca8b.b2fc78"]]},{"id":"e4f1ca8b.b2fc78","type":"debug","z":"f5d634f3.9e4378","name":"","active":true,"console":"false","complete":"false","x":1002,"y":1968,"wires":[]},{"id":"1b96d3cb.58379c","type":"inject","z":"f5d634f3.9e4378","name":"","topic":"sensors/sensor1","payload":"ON","payloadType":"str","repeat":"","crontab":"","once":false,"x":1230,"y":1980,"wires":[["23d111ba.491d7e"]]},{"id":"23d111ba.491d7e","type":"function","z":"f5d634f3.9e4378","name":"Global -4","func":"\nvar count=flow.get('count') || 0;\nvar gcount=global.get('count') || 0;\n\ncount -=4;\nmsg.payload=\"F10 \"+\" flow= \"+count+ \"  global= \"+gcount;\nflow.set('count',count);\nglobal.set('count',gcount);\nreturn msg;","outputs":1,"noerr":0,"x":1369,"y":1887,"wires":[["36803a1e.594846"]]},{"id":"36803a1e.594846","type":"debug","z":"f5d634f3.9e4378","name":"","active":true,"console":"false","complete":"false","x":1542,"y":1968,"wires":[]}]

After incorporating everything so far, has anyone got any tips for further development / simplification?
Thanks

You never increase or decrease global.count only flow.count those are different variables.

That's what I'm now finding! Now I know why, thanks. I'm now working on a 'switch' node to send IR commands to the amp based on the 'flow count' number, and also a way to reference that number and adjust the volume accordingly. Any tips?

Hmm, it seems I need some kind of 'if' statement rules for 'if the previous flow count vol = (?) then add or subtract x' to account for changing channels (quiet channel to loud, quiet to quiet, loud to loud, loud to quiet). So I need to store TWO variables and have some function to be able to compare them. That is the limit of my learning so far! Any help?

You could do this in a function node or in base nodes. Think of the switch node as your if statement you could have one condition test something and add another rule with the ‘otherwise’ so you would have two outputs from the switch and you add more nodes to do what you want on each of the flow paths.

Thanks for your reply, I have made a little progress. So far I have a switch node with outputs for 'if less than 36 = ouput 1', in multiples of 4 up to 'if above 52 = output 5'. But I need to reference what the previous volume was to be able to know if I should + or - volume.
The (HDMI 1 input) starting/ending value is 40,
TV input starting value should be 36,
any HD channel should be 32,
any non HD is 36.
The only way I can imagine a way forwards is to poll the flow count volume before choosing the channel (store it) then compare it to the HD/non HD (I have a is-it-HD-or-not switch for each) volume value and send up/down volume commands based on that. And to keep check on the volume in case it goes haywire. That is where I feel a function node would be needed and where I'm stuck.

So I'm confused. You talk about different inputs of the screen - i.e. tv, hdmi1 and HD then you talk about channels.

So are do you mean you need to keep track of the volume on each channel so you can switch to the last volume of that channel? or is it by input?

Any way here is a rough idea of what I try. Create a flow object called 'volume' with sub variables called 'hdmi1', 'hemi2' etc so at the start you would have a change node that set:

flow.volume.hdmi1 = 0
flow.volume.hdmi2 = 0
flow.volume.tv = 0
flow.volume.hd = 0
flow.volume.current = 0

Then when an input, if you switched devices you first set volume.xxxxx (xxxxx = the current device) to volume.current. You then grab volume.yyyyy (yyyyy = the device you are switching to) and set volume.currrent to volume.yyyyy and write them ack to the flow variable.

If you are just increasing/decreasing the volume add or subtract the change from volume.current and volume.xxxxx and write them back to the flow variable.

Great, this is the change of direction I needed. I got caught up in over-complicating things and believed I needed a magic function node with lots of arcane code in it to sort it out!
Sorry about the confusion, I was trying to define the variables needed. For clarification - The amplifier and tv are either off or on PC input (HDMI2) @ 40 volume, switching to TV input should reduce the volume to a starting value of 36. From there it's either an HD TV 'station' (channel in the U.K :wink:) = volume 32 or back to 36 for non-HD station. Which, programmatically speaking would be easier than trying to keep tabs on a running total and adding or subtracting from it every time. Well I've got some more learning to do but I think I'm now on the right track! Thanks alot @zenofmud

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