Node Red + Update Input Number Value + Volumio

Long story short, I have an esphome NodeMCU with a rotary button to change the volume of a volumio integration (this works). On the NodeMCU, I also have an SSD1306 Display that shows the value of the rotary encoder / volumio volume. This is fine if I only want to change the volumio volume from the rotary button, but if I change it in volumio, OR through a node-red trigger, I would like the rotary value / screen to update as well. I can also change the volume of volumio from an input number slider.

What I would like to do is set the value of the same Input Number to the value of volumio volume when I pass in the value from the node-red trigger, that then goes into a function node, but I keep getting an error of “Call-service API error. Error Message: required key not provided @ data[‘value’]” I am new to node-red, so hopefully you have ideas, resources to point me towards. I am wondering if a

Any hints?

Here is a screenshot, I’ll figure out how to post the flow tonight. This is the full screenshot for something I am working on called Porch Mode. So when I open my porch door I can have volumio music automatically play and lights turn on if the sun is below the horizon.

[{"id":"b9d7a859.d7d0c8","type":"server-state-changed","z":"8f0283d1.757e7","name":"Patio Door Violated","server":"97501cec.c3c92","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.zone_012","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"Violated","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":130,"y":880,"wires":[["3326b8fb.b6ef28"],[]]},{"id":"634c9370.a3622c","type":"trigger","z":"8f0283d1.757e7","name":"Send Play to Volumio","op1":"play","op2":"play","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"Normal","bytopic":"all","topic":"topic","outputs":1,"x":860,"y":920,"wires":[["e3569873.b84578"]]},{"id":"e3569873.b84578","type":"function","z":"8f0283d1.757e7","name":"Volumio String","func":"var event = msg.payload;\n\nmsg.payload = {\n    event: event\n    \n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1260,"y":940,"wires":[["e542ccca.cbcd2"]]},{"id":"e542ccca.cbcd2","type":"volumio command","z":"8f0283d1.757e7","server":"ec39db10.92fad8","x":1570,"y":940,"wires":[[]]},{"id":"bc7f6575.19e688","type":"switch","z":"8f0283d1.757e7","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":590,"y":880,"wires":[["634c9370.a3622c","da5337c6.2692e8","a2a121d8.b38e"],[]]},{"id":"3326b8fb.b6ef28","type":"api-current-state","z":"8f0283d1.757e7","name":"Porch Mode On?","server":"97501cec.c3c92","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"switch.output_063","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":370,"y":880,"wires":[["bc7f6575.19e688"],[]]},{"id":"88861e.97d869e","type":"trigger","z":"8f0283d1.757e7","name":"Send Stop to Volumio","op1":"stop","op2":"stop","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"on","bytopic":"all","topic":"topic","outputs":1,"x":860,"y":1040,"wires":[["e3569873.b84578"]]},{"id":"9b84c935.2d0cb8","type":"switch","z":"8f0283d1.757e7","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":650,"y":1040,"wires":[[],["88861e.97d869e","4fa1a359.c89fec","ed0ca7ee.ca2e58"]]},{"id":"3315aa79.ebfff6","type":"server-state-changed","z":"8f0283d1.757e7","name":"Porch Mode State Off","server":"97501cec.c3c92","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"switch.output_063","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":140,"y":1040,"wires":[["9b84c935.2d0cb8"],[]]},{"id":"2c2d631.4d95f9c","type":"api-call-service","z":"8f0283d1.757e7","name":"Turn On Porch String Lights","server":"97501cec.c3c92","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.sonoff_1000d2b03c","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1280,"y":860,"wires":[[]]},{"id":"4fa1a359.c89fec","type":"api-call-service","z":"8f0283d1.757e7","name":"Turn Off Porch String Lights","server":"97501cec.c3c92","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.sonoff_1000d2b03c","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":880,"y":1200,"wires":[[]]},{"id":"da5337c6.2692e8","type":"trigger","z":"8f0283d1.757e7","name":"Set Porch Angel to Volume 60","op1":"60","op2":"60","op1type":"num","op2type":"num","duration":"250","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":890,"y":760,"wires":[["6473cb60.dc84a4"]]},{"id":"6473cb60.dc84a4","type":"function","z":"8f0283d1.757e7","name":"Volumio Volume Function","func":"var vol = msg.payload;\n\nmsg.payload = {\n    event: \"volume\",\n    data: vol\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1270,"y":1020,"wires":[["e542ccca.cbcd2"]]},{"id":"224be521.75b39a","type":"inject","z":"8f0283d1.757e7","name":"Test On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":350,"y":800,"wires":[["bc7f6575.19e688"]]},{"id":"4871eb96.bb6154","type":"inject","z":"8f0283d1.757e7","name":"Test Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":370,"y":1100,"wires":[["9b84c935.2d0cb8"]]},{"id":"ed0ca7ee.ca2e58","type":"trigger","z":"8f0283d1.757e7","name":"Set Porch Angel to Volume 20","op1":"20","op2":"20","op1type":"num","op2type":"num","duration":"250","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":890,"y":1280,"wires":[["6473cb60.dc84a4"]]},{"id":"a2a121d8.b38e","type":"api-current-state","z":"8f0283d1.757e7","name":"Sun Below Horizon?","server":"97501cec.c3c92","version":1,"outputs":2,"halt_if":"below_horizon","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sun.sun","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":860,"y":840,"wires":[["2c2d631.4d95f9c"],[]]},{"id":"150cf551.11d6eb","type":"server-state-changed","z":"8f0283d1.757e7","name":"Porch Angel Volume Rotart","server":"97501cec.c3c92","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.porch_angel_volume","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"0","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"output_only_on_state_change":true,"x":890,"y":1360,"wires":[["6473cb60.dc84a4"],[]]},{"id":"fd6092b3.6a487","type":"trigger","z":"8f0283d1.757e7","name":"Send Stop to Volumio","op1":"stop","op2":"stop","op1type":"str","op2type":"str","duration":"250","extend":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":860,"y":1120,"wires":[["e3569873.b84578"]]},{"id":"9b887ff1.14f31","type":"server-state-changed","z":"8f0283d1.757e7","name":"Input Number","server":"97501cec.c3c92","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.porchangeltest","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"0","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"output_only_on_state_change":true,"x":830,"y":980,"wires":[["6473cb60.dc84a4"],[]]},{"id":"97501cec.c3c92","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true},{"id":"ec39db10.92fad8","type":"volumio-server","z":"","host":"192.168.1.51","port":"3000"}]

So I am trying to simplify it. I want to change the value of Input number from the gui, maybe have it pass through a function, and then set the value of the same input number on the other side. The debug node after the function says:

input_number.porchangeltest : msg.value : number
33

The call service node either tells me “Call-service API error. Error Message: required key not provided @ data[‘value’]” OR “Call-service API error. Error Message: extra keys not allowed @ data[‘0’]”

call service looks like it needs this info:
image

I will try to watch more videos on Functions, but maybe y’all have some insight.

I can set the value in Home Assistant using"

entity_id: input_number.porchangeltest
value: 23

But I cant seem to translate this to node red.

[{"id":"22c1db8.69c8c24","type":"debug","z":"8f0283d1.757e7","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"value","targetType":"msg","statusVal":"","statusType":"auto","x":550,"y":1880,"wires":[]},{"id":"e51582fc.35ea","type":"api-call-service","z":"8f0283d1.757e7","name":"Input Number","server":"97501cec.c3c92","version":1,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.porchangeltest","data":"msg.value","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":560,"y":1780,"wires":[["4c706164.40599"]]},{"id":"9e374b6e.d3a3f8","type":"server-state-changed","z":"8f0283d1.757e7","name":"Input Number","server":"97501cec.c3c92","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.porchangeltest","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"0","halt_if_type":"num","halt_if_compare":"gte","outputs":2,"output_only_on_state_change":true,"x":130,"y":1780,"wires":[["630171c5.dccc3","30e27257.4bd97e"],[]]},{"id":"630171c5.dccc3","type":"function","z":"8f0283d1.757e7","name":"","func":"var value = msg.payload;\nmsg.value = value\n\nmsg.payload  = {\n    \n    value: \"value\",\n\n}\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":1780,"wires":[["e51582fc.35ea","22c1db8.69c8c24"]]},{"id":"30e27257.4bd97e","type":"debug","z":"8f0283d1.757e7","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":310,"y":1880,"wires":[]},{"id":"4c706164.40599","type":"debug","z":"8f0283d1.757e7","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":1780,"wires":[]},{"id":"97501cec.c3c92","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Not exactly sure how you want to modify the value of the input_number in the function node based off your example.

Here’s an example if you want to add 2 to the value.

const origValue = msg.payload;
const newValue = origValue + 2;

msg.payload  = { 
    "data": {   
        value: newValue
    }
}

return msg;

Also, in the call-service leave the data field empty.

Thank You Kermit!

I sent this:

const origValue = msg.payload;
const newValue = origValue;

msg.payload  = { 
    "data": {   
        value: newValue
    }
}

return msg;

This got around the API Error. I have some learning to understand why this works. What I am trying to accomplish is to make sure that no matter where I change the volume I want it to display the current volume on my esphome display. So if I change it via the rotary button, or eventually volumio, it updates a “master” volume every device looks to, which I imagine should be the volumio volume. I think my plan-a created a big loop and I had to clear some nodes to stop it. I might need to look into getting the volumio volume back to node red somehow, then maybe back to the screen.

If you have thoughts, suggestions please let me know. Thanks again

Here’s an example showing if either the input_number or rotary sensor changes it updates the volumio volume. This should allow you to use the homeassistant sensor in ESPHome to display that value in the Display. I am only guessing here as I’ve never used a display on a nodemcu.

set_volume expects the volume to be a decimal between 0 and 1. Not sure what your rotary sensor outputs so you’ll probably have to modify that value also.

[{"id":"a4174453.c2b2d8","type":"server-state-changed","z":"ffbd7f06.4a014","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.porchangeltest","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":266,"y":1104,"wires":[["e48d7fb6.87845"]]},{"id":"a21a8010.1ffff","type":"api-call-service","z":"ffbd7f06.4a014","name":"","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.volumio","data":"{\"volume_level\": {{payload}} }","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":930,"y":1104,"wires":[[]]},{"id":"e2a5946e.b3b8c8","type":"server-state-changed","z":"ffbd7f06.4a014","name":"","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.rotary_wheel","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":236,"y":1152,"wires":[["cbf4a983.121668"]]},{"id":"e48d7fb6.87845","type":"function","z":"ffbd7f06.4a014","name":"convert to decimal percent","func":"msg.payload = msg.payload / 100;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":584,"y":1104,"wires":[["a21a8010.1ffff"]]},{"id":"cbf4a983.121668","type":"function","z":"ffbd7f06.4a014","name":"also need to be convert to a decimal?","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":614,"y":1152,"wires":[["a21a8010.1ffff"]]}]

Home Assistant
Template sensor to breakout volumio volume level

# Example configuration.yaml entry
sensor:
  - platform: template
    sensors:
      volumio_volume_level:
        friendly_name: "volumio volume level"
        value_template: "{{ state_attr('media_player.volumio', 'volume_level') }}"

ESPHome

# Example configuration entry
sensor:
  - platform: homeassistant
    name: "Volumio volume level"
    entity_id: sensor.volumio_volume_level