Hello
I am using Google Home as a doorbell chime, linked to an Aqara wireless switch in a Node-red flow. The flow grabs the media player current state so it can later restore the volume and also decide whether to restart the radio stream. The chime works fine and after playing, the home returns the volume to its prior state. The problem I am having is how to reliably return the home to the radio station that was playing. For now, I am happy to hardcode to 1 station (BBC Radio 2) - so if it was playing then I want it to simply start it up again after the chime. In the future I’d like to make this a bit more dynamic but one step at a time for now.
I have pasted my flow below (with inject buttons for testing). The “Play” button works great, Radio 2 starts up every time although note that I have to call play_media twice for some reason. The first simply turns the Home from off to idle then the second one starts playback. Replacing the first call with turn_on did not work reliably. When this part of the flow is triggered from the Test button after playing the chime, the radio doesn’t play. In the Google Home Android app, it shows as “playing” with the name of the station showing but there is no sound and no pause button. All I can do in the app is change the volume or stop casting.
I’m not sure if this problem is unique to BBC Sounds or my chime nodes are doing something to the Google Home that messes up the subsequent radio cast or if I’m doing something else wrong in Node Red. I’ve been trying to get this working for a few weeks! Any help welcome. Thanks in advance.
Useful links: https://community.home-assistant.io/t/google-cast-play-media-from-app-bbc-radio/305644
https://www.home-assistant.io/integrations/cast/
This is what I am trying to achieve:
-
Button is pressed
-
Get speaker state
-
If its off, turn it on and wait until its not off
-
Set vol to a desired level (currently 5% so I don’t annoy my family trying to get it to work!)
-
Play chime
-
Wait 25s for it to finish
-
Reset the volume (currently working if fed from a function as I couldn’t set vol to a previously captured variable in the service node (string vs float or general syntax errors)
-
If previously captured content id was bbc_radio_two then cast this again (the broken bit)
-
Wait a few secs and repeat step 8 if its not playing (happy to lose this step if anyone knows why I’m having to repeat it!)
[{"id":"7d27e0b530feec59","type":"inject","z":"e5a279481ebabf5f","name":"Test","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":90,"y":340,"wires":[["cb49f1bb55e105b3"]]},{"id":"cb49f1bb55e105b3","type":"api-current-state","z":"e5a279481ebabf5f","name":"Speaker","server":"a8e8332.92727d","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"media_player.kitchen_speaker","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"speaker_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":120,"y":260,"wires":[["b749f7c59eb60e01"]]},{"id":"b749f7c59eb60e01","type":"switch","z":"e5a279481ebabf5f","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"},{"t":"neq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":260,"wires":[["0688c2a95877999f"],["3e7b36c7713bb008"]]},{"id":"0688c2a95877999f","type":"api-call-service","z":"e5a279481ebabf5f","name":"Speaker On","server":"a8e8332.92727d","version":3,"debugenabled":false,"service_domain":"media_player","service":"turn_on","entityId":"media_player.kitchen_speaker","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":450,"y":220,"wires":[["5053a5bfada1a4b7"]]},{"id":"5053a5bfada1a4b7","type":"ha-wait-until","z":"e5a279481ebabf5f","name":"","server":"a8e8332.92727d","version":0,"outputs":2,"entityId":"media_player.kitchen_speaker","entityIdFilterType":"exact","property":"state","comparator":"is_not","value":"off","valueType":"str","timeout":"5","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"data","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":600,"y":220,"wires":[["6a940cab9da17b71"],[]]},{"id":"6a940cab9da17b71","type":"api-current-state","z":"e5a279481ebabf5f","name":"Speaker","server":"a8e8332.92727d","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"media_player.kitchen_speaker","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"speaker_data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":760,"y":220,"wires":[["3e7b36c7713bb008"]]},{"id":"3e7b36c7713bb008","type":"api-call-service","z":"e5a279481ebabf5f","name":"Set Vol","server":"a8e8332.92727d","version":3,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.kitchen_speaker","data":"{\"volume_level\": 0.05}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":440,"y":300,"wires":[["792f7a13d192b31d"]]},{"id":"792f7a13d192b31d","type":"api-call-service","z":"e5a279481ebabf5f","name":"Chime","server":"a8e8332.92727d","version":3,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"media_player.kitchen_speaker","data":"{\"media_content_type\": \"audio/mp3\", \"media_content_id\":\"http://192.168.1.65:8123/local/Doorbell_Let_Em_In.mp3\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":590,"y":300,"wires":[["d6dfe34522338967"]]},{"id":"d6dfe34522338967","type":"delay","z":"e5a279481ebabf5f","name":"","pauseType":"delay","timeout":"25","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":440,"y":360,"wires":[["4445ee5bf0444b5f","3f6f1aa2776397a1"]]},{"id":"4445ee5bf0444b5f","type":"function","z":"e5a279481ebabf5f","name":"","func":"msg.payload =\n{\n \"data\":{\n \"entity_id\":\"media_player.kitchen_speaker\",\n \"volume_level\": msg.speaker_data.attributes.volume_level \n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":360,"wires":[["225b505e028da429"]]},{"id":"225b505e028da429","type":"api-call-service","z":"e5a279481ebabf5f","name":"Reset Vol","server":"a8e8332.92727d","version":3,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"","data":"{} ","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":760,"y":360,"wires":[[]]},{"id":"3f6f1aa2776397a1","type":"switch","z":"e5a279481ebabf5f","name":"","property":"speaker_data.attributes.media_content_id","propertyType":"msg","rules":[{"t":"eq","v":"bbc_radio_two","vt":"str"},{"t":"eq","v":"bbc_radio_five_live","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":590,"y":420,"wires":[["cc393b61b13bf77d"],["1a3107010771ee49"]]},{"id":"1a3107010771ee49","type":"api-call-service","z":"e5a279481ebabf5f","name":"R5","server":"a8e8332.92727d","version":3,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"media_player.kitchen_speaker","data":"{ \"media_content_type\": \"cast\", \"media_content_id\": \" { \\\"app_name\\\": \\\"bbcsounds\\\", \\\"media_id\\\": \\\"bbc_radio_five_live\\\", \\\"is_live\\\": true }\", \"extra\": { \"metadata\": { \"metadataType\": 0, \"title\": \"Radio 5 live\", \"images\": [ { \"url\": \"https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_five_live/background_1280x720.png\" } ] } } }","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":750,"y":480,"wires":[[]]},{"id":"ce80de8d0a2432a1","type":"api-current-state","z":"e5a279481ebabf5f","name":"Speaker","server":"a8e8332.92727d","version":3,"outputs":2,"halt_if":"playing","halt_if_type":"str","halt_if_compare":"is_not","entity_id":"media_player.kitchen_speaker","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1000,"y":420,"wires":[["b96d05fa49709507"],[]]},{"id":"947b8325c4211ac7","type":"delay","z":"e5a279481ebabf5f","name":"12s","pauseType":"delay","timeout":"12","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":870,"y":420,"wires":[["ce80de8d0a2432a1"]]},{"id":"b96d05fa49709507","type":"api-call-service","z":"e5a279481ebabf5f","name":"R2","server":"a8e8332.92727d","version":3,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"media_player.kitchen_speaker","data":"{\t \"media_content_type\": \"cast\",\t \"media_content_id\": \" { \\\"app_name\\\": \\\"bbcsounds\\\", \\\"media_id\\\": \\\"bbc_radio_two\\\", \\\"is_live\\\": true }\",\t \"extra\": {\t \"metadata\": {\t \"metadataType\": 0,\t \"title\": \"Radio 2\",\t \"images\": [\t {\t \"url\": \"https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_two/background_1280x720.png\"\t }\t ]\t }\t }\t }","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1130,"y":420,"wires":[[]]},{"id":"cc393b61b13bf77d","type":"api-call-service","z":"e5a279481ebabf5f","name":"R2","server":"a8e8332.92727d","version":3,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"media_player.kitchen_speaker","data":"{\t \"media_content_type\": \"cast\",\t \"media_content_id\": \" { \\\"app_name\\\": \\\"bbcsounds\\\", \\\"media_id\\\": \\\"bbc_radio_two\\\", \\\"is_live\\\": true }\",\t \"extra\": {\t \"metadata\": {\t \"metadataType\": 0,\t \"title\": \"Radio 2\",\t \"images\": [\t {\t \"url\": \"https://sounds.files.bbci.co.uk/2.3.0/networks/bbc_radio_two/background_1280x720.png\"\t }\t ]\t }\t }\t }","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":730,"y":420,"wires":[["947b8325c4211ac7"]]},{"id":"853f8c097d73fcfe","type":"inject","z":"e5a279481ebabf5f","name":"Play","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":530,"y":500,"wires":[["cc393b61b13bf77d"]]},{"id":"a8e8332.92727d","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]