Can I set volume of Alexa Announcement?

{
    "data": {
        "volume_level": "0.8"
    }
}

this is giving me an error

1 Like

Please post the whole node. Are you using the media_player set volume service call?
image
This should be working

I feel like you cant set volume of announcement

You also need to specify an entity, the media player you want to set the volume off

yep I left out the entity specifically…thanks!!

Maybe I didn’t understand the problem in the first place. You cannot just set the volume of an annoucement, you have to set the volume of the whole player.

However, what you could do is the following:

Whenever you send an announcement:

1.Check the current volume
2.Save it
3.Set the Volume you want for the announcement
4.Wait until the annoucement has played (i usually just set 2-3 sec)
5.Restore the saved volume to the Echo devices.

I did that for some time, but it turns out when you want to change a lot of echo devices at the same time some of the devices do not actually follow the command. So you would probably need to play around with some delays.

1 Like

I could’ve posed the question much clearer - yes, I wanted to set the volume on any device(s) prior to making the Announcement, so your advice on being sure to include the entity_id in the set_volume service-call was spot on!

1.Check the current volume
2.Save it

I’m trying to figure out to save the current volume of the device(s) now…struggling a bit.

the current volume probably is in a message like this:

data.new_state.attributes.volume_level

You can save that with a formula node


Here is an example (not with alexa though)

[
    {
        "id": "45dda31f.44616c",
        "type": "function",
        "z": "8a2eb1df.353f7",
        "name": "Save Settings",
        "func": "msg.volume = msg.payload\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 800,
        "y": 3540,
        "wires": [
            [
                "26d9e9d7.7e9766"
            ]
        ]
    },
    {
        "id": "491e7ba6.c0ae34",
        "type": "function",
        "z": "8a2eb1df.353f7",
        "name": "Previous time",
        "func": "newmsg = {}\n\nnewmsg.payload = { data: { \"value\":msg.volume} }\n\nreturn newmsg;",
        "outputs": 1,
        "noerr": 0,
        "x": 1280,
        "y": 3540,
        "wires": [
            [
                "377b0661.7ed4ca"
            ]
        ]
    },
    {
        "id": "fdd013f4.b775c",
        "type": "api-current-state",
        "z": "8a2eb1df.353f7",
        "name": "Volume?",
        "server": "2fba4297.e4145e",
        "version": 1,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "input_number.cast_uberall",
        "state_type": "str",
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 640,
        "y": 3540,
        "wires": [
            [
                "45dda31f.44616c"
            ]
        ]
    },
    {
        "id": "faf031d7.6150a",
        "type": "ha-wait-until",
        "z": "8a2eb1df.353f7",
        "name": "",
        "server": "2fba4297.e4145e",
        "outputs": 1,
        "entityId": "sensor.marcus_call",
        "property": "state",
        "comparator": "is",
        "value": "idle",
        "valueType": "str",
        "timeout": 0,
        "timeoutUnits": "seconds",
        "entityLocation": "",
        "entityLocationType": "none",
        "checkCurrentState": true,
        "blockInputOverrides": true,
        "x": 1120,
        "y": 3540,
        "wires": [
            [
                "491e7ba6.c0ae34"
            ]
        ]
    },
    {
        "id": "377b0661.7ed4ca",
        "type": "api-call-service",
        "z": "8a2eb1df.353f7",
        "name": "",
        "server": "2fba4297.e4145e",
        "version": "1",
        "service_domain": "input_number",
        "service": "set_value",
        "entityId": "input_number.cast_uberall",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 1500,
        "y": 3540,
        "wires": [
            []
        ]
    },
    {
        "id": "26d9e9d7.7e9766",
        "type": "api-call-service",
        "z": "8a2eb1df.353f7",
        "name": "Set Volume",
        "server": "2fba4297.e4145e",
        "version": "1",
        "service_domain": "input_number",
        "service": "set_value",
        "entityId": "input_number.cast_uberall",
        "data": "{\"value\":\"10\"}",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 970,
        "y": 3540,
        "wires": [
            [
                "faf031d7.6150a"
            ]
        ]
    },
    {
        "id": "2fba4297.e4145e",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "legacy": false,
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true
    }
]

ok so im grabbing the value of the attribute, storing in a function via

msg.volume = msg.data.attributes.volume_level;
return msg;

but I’m confused about what Im passing into the Data portion of call service node:

{{“volume_level”:‘msg.volume’} says extra keys not allowed

you would use either a function node or

{“volume_level”:{{volume}} }

hmmm, this didnt work either

{“volume_level”:{{volume}}}

i know I’m doing something wrong

[{"id":"ab9e052e.e8d85","type":"api-call-service","z":"6827442a.0b7524","name":"Set Volume to 80%","server":"2dfba141.2a4c5e","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.everywhere","data":"{{payload}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1450,"y":100,"wires":[[]]},{"id":"2dfba141.2a4c5e","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

So when I’m not completely mistaken you should actually need {{{payload}}} because you always need to wrap it in brackets. The double bracket {{ }} is for a variable. However, depending on whats in your payload, you will still need to add the variable of “volume_level” in there. So if your msg.payload is only the value, i.e.: “0.5” then you would need to write:

{“volume_level”:{{payload}}}

However, In my experience it works better with just sending the whole data field via a function node and leaving the data field empty. As in my example i sent you:

newmsg = {}

newmsg.payload = { data: { "volume_level":msg.volume} }

return newmsg;

So just write it in the function node (the extra {data:} is important, instead of writing something like this: {“volume_level”:“0.5”} into the field.

Did you manage to solve this? If so, can you please share the flow?

[{“id”:“5a07cb3a.91ebd4”,“type”:“api-call-service”,“z”:“673571fc.d42f2”,“name”:“Set Volume to 80%”,“server”:“ff0019af.a1b94”,“version”:1,“debugenabled”:false,“service_domain”:“media_player”,“service”:“volume_set”,“entityId”:“media_player.kitchen_echo, media_player.addie_echo, media_player.salon_echo”,“data”:"{“volume_level”:“0.7”}",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1190,“y”:120,“wires”:[[“47a6ef6e.a8574”]]},{“id”:“ff0019af.a1b94”,“type”:“server”,“name”:“Home Assistant Docker”,“legacy”:false,“addon”:false,“rejectUnauthorizedCerts”:true,“ha_boolean”:“y|yes|true|on|home|open”,“connectionDelay”:true,“cacheJson”:true}]

Thanks bigverm23. I tried to import your example (and after I had sorted the double quotes got an error message as follows:

SyntaxError: Unexpected token v in JSON at position 312

I believe you don’t need quotes before and after those curly brackets.

"data":{"volume_level":"0.7"}

for that particular purpose, I would use: node-red-contrib-alexa-remote2
there’s a ‘Speak at volume’ feature that allows you to do exactly that. Turns volume up during message, and rolls back to previous volume.

Not only for that, node-red-contrib-alexa-remote2 to me is more powerful in NR that the Alexa media player for various reasons

1 Like

Hi guys, I just tested this and could set the volume no problem:

image

Hope this helps someone

4 Likes