Hi, I’m very new to Node-RED and having great fun learning. I’ve been trying to work on a pretty typical sequence for a Doorbell chime.
I’ve used a lot of information from this post.
Basically it boils down to:
- Doorbell pressed
- Capture current volume of all Alexa devices
- Increase Volume to 90% for all Alexa devices
- Play Chime
- Revert Volume back
I have managed to achieve this (after an embarrassing amount of time figuring it out) with the following:
[{"id":"393db8d.1060848","type":"api-current-state","z":"6c7101b0.e0c0a","name":"Echo Show Volume?","server":"bcca64cb.debed8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.george_s_echo_show","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":480,"y":620,"wires":[["2346232e.a7630c"]]},{"id":"2346232e.a7630c","type":"change","z":"6c7101b0.e0c0a","name":"Extract Current Volume","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.volume_level","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":620,"wires":[["7d88e206.6a978c"]]},{"id":"5b70f2f7.eec36c","type":"api-call-service","z":"6c7101b0.e0c0a","name":"Increase Vol. to 90%","server":"bcca64cb.debed8","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.george_s_echo_show, media_player.george_s_echo_dot, media_player.george_s_echo, media_player.george_s_sonos_one","data":"{\"volume_level\":\"0.9\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":700,"y":860,"wires":[["f474c76e.3548d8"]]},{"id":"6ef2e671.997bb8","type":"api-call-service","z":"6c7101b0.e0c0a","name":"Revert Vol.","server":"bcca64cb.debed8","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.george_s_echo_show","data":"{\"volume_level\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":620,"wires":[[]]},{"id":"f474c76e.3548d8","type":"api-call-service","z":"6c7101b0.e0c0a","name":"Play Chime","server":"bcca64cb.debed8","version":1,"debugenabled":false,"service_domain":"media_player","service":"play_media","entityId":"media_player.george_s_echo_show, media_player.george_s_echo_dot, media_player.george_s_echo, media_player.george_s_sonos_one","data":"{\"media_content_id\":\"amzn_sfx_doorbell_chime_01\",\"media_content_type\":\"sound\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":970,"y":860,"wires":[[]]},{"id":"7d88e206.6a978c","type":"delay","z":"6c7101b0.e0c0a","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":940,"y":620,"wires":[["6ef2e671.997bb8"]]},{"id":"e1ad8bc8.459ac8","type":"api-current-state","z":"6c7101b0.e0c0a","name":"Echo Volume?","server":"bcca64cb.debed8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.george_s_echo","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":460,"y":680,"wires":[["6ff5f09b.dd361"]]},{"id":"80d9862f.a02cc8","type":"api-current-state","z":"6c7101b0.e0c0a","name":"Echo Dot Volume?","server":"bcca64cb.debed8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.george_s_echo_dot","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":470,"y":740,"wires":[["8783ccd9.a7497"]]},{"id":"9a17f5f7.2d7918","type":"api-current-state","z":"6c7101b0.e0c0a","name":"Sonos Volume?","server":"bcca64cb.debed8","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"media_player.george_s_sonos_one","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":460,"y":800,"wires":[["4ebbd74e.4c8248"]]},{"id":"6ff5f09b.dd361","type":"change","z":"6c7101b0.e0c0a","name":"Extract Current Volume","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.volume_level","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":680,"wires":[["91c6387d.3f9148"]]},{"id":"8783ccd9.a7497","type":"change","z":"6c7101b0.e0c0a","name":"Extract Current Volume","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.volume_level","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":740,"wires":[["df96f779.f0bcb8"]]},{"id":"4ebbd74e.4c8248","type":"change","z":"6c7101b0.e0c0a","name":"Extract Current Volume","rules":[{"t":"set","p":"payload","pt":"msg","to":"data.attributes.volume_level","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":800,"wires":[["e989936.ab50c7"]]},{"id":"cf84316b.e8add","type":"api-call-service","z":"6c7101b0.e0c0a","name":"Revert Vol.","server":"bcca64cb.debed8","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.george_s_echo","data":"{\"volume_level\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":680,"wires":[[]]},{"id":"91c6387d.3f9148","type":"delay","z":"6c7101b0.e0c0a","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":940,"y":680,"wires":[["cf84316b.e8add"]]},{"id":"f2b8d75a.0329b8","type":"api-call-service","z":"6c7101b0.e0c0a","name":"Revert Vol.","server":"bcca64cb.debed8","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.george_s_echo_dot","data":"{\"volume_level\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":740,"wires":[[]]},{"id":"df96f779.f0bcb8","type":"delay","z":"6c7101b0.e0c0a","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":940,"y":740,"wires":[["f2b8d75a.0329b8"]]},{"id":"4bd2d0ce.adf9c","type":"api-call-service","z":"6c7101b0.e0c0a","name":"Revert Vol.","server":"bcca64cb.debed8","version":1,"debugenabled":false,"service_domain":"media_player","service":"volume_set","entityId":"media_player.george_s_sonos_one","data":"{\"volume_level\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":800,"wires":[[]]},{"id":"e989936.ab50c7","type":"delay","z":"6c7101b0.e0c0a","name":"","pauseType":"delay","timeout":"4","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":940,"y":800,"wires":[["4bd2d0ce.adf9c"]]},{"id":"9d5a44d.6f3f5b8","type":"delay","z":"6c7101b0.e0c0a","name":"","pauseType":"delay","timeout":"250","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":450,"y":860,"wires":[["5b70f2f7.eec36c"]]},{"id":"85319993.09ff38","type":"server-events","z":"6c7101b0.e0c0a","name":"Doorbell Press","server":"bcca64cb.debed8","event_type":"doorbird_doorbell_button","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":120,"y":740,"wires":[["393db8d.1060848","e1ad8bc8.459ac8","9a17f5f7.2d7918","80d9862f.a02cc8","9d5a44d.6f3f5b8","2906112a.a4694e"]]},{"id":"2906112a.a4694e","type":"api-call-service","z":"6c7101b0.e0c0a","name":"Alert TV","server":"bcca64cb.debed8","version":1,"debugenabled":false,"service_domain":"notify","service":"lounge_tv","entityId":"","data":"{\"message\":\"Doorbell\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":440,"y":920,"wires":[[]]},{"id":"bcca64cb.debed8","type":"server","name":"Home Assistant","addon":true}]
However, I don’t think its the most efficient way of doing things, so it would be great to get some feedback from more experienced users. I feel like things could be condensed more with a function node, but I do like the visibility of the current setup.
Speed is the most important factor, and naturally grabbing the volume attribute of each device does slow things down a little when compared to going direct to a call service node, I’ve tried to mitigate this by using a very short delay before running the Increase Vol. to 90% node. Do you think this is best or would it just be as fast (or faster) to have the Increase Vol. to 90% node triggered by the payload from the Extract Current Volume nodes?
Also, its a bit of a bodge with the 4 second delay, it would be cleaner to have a the Revert Vol. nodes kick in after the chime has played but I’m not entirely sure how to set that up.
And finally, as for the Doorbell Press ‘events: all’ node; is it best practice to avoid this node when possible? Would an events state node be a faster (or perhaps less resource heavy) option? The only issue I have with the events state node is that I’m using the Doorbird Integration which triggers an event on doorbell press so doesn’t have an entity that I could use, so I’m unsure on how that would work.
Any feedback would be greatly appreciated, thanks.
G