Speed up automation

Hi everyone.

Is there a way to speed up this automation, so that I don’t have to wait 3 sec before my doorbell sound plays. Right now it’s to slow.

Any (helpful) comments are highly appreciated!:slightly_smiling_face:

alias: Ringklokke
description: ''
trigger:
  - platform: device
    device_id: efbc6695aef4fc18f5ca64fe811c15fc
    domain: shelly
    type: single
    subtype: button
condition: []
action:
  - service: sonos.snapshot
    data:
      entity_id: media_player.sonos_alrum
  - delay:
      hours: 0
      minutes: 0
      seconds: 1
      milliseconds: 0
  - service: media_player.volume_set
    data:
      volume_level: 0.6
    target:
      entity_id: media_player.sonos_alrum
  - service: media_player.play_media
    data:
      entity_id: media_player.sonos_alrum
      media_content_id: http://192.168.1.48:8123/local/Ringklokke01.mp3
      media_content_type: music
  - delay:
      seconds: 5
  - service: media_player.volume_set
    data:
      volume_level: 0.15
    target:
      entity_id: media_player.sonos_alrum
  - service: sonos.restore
    data:
      entity_id: media_player.sonos_alrum
mode: single

It’s hard to optimize it more, since it’s just script commands in a sequence.
You might be able to move the volume_set command up before the delay without it affecting anything, but you will have to test it.
Besides that you can not in the script optimize more as such.

You can play a bit with the Ringklokke01 sound, like loading it into a sound editor, like Audacity and see if there is some silence in the start that can be removed and you might also be able to gain a few milliseconds by using a wave instead of a mp3, but again you need to test this to be sure.

1 Like

I bet that it’s all on the sonos end and you can’t do much to improve it. Try triggering the automation manually by clicking the “run actions” button on your automations page to make sure that it’s not the shelly.

Other ideas:

  • Use a carefully placed motion sensor to trigger the doorbell instead of someone pressing it to get a head start
  • Get an off-the-shelf buzzer that integrates into home asssistant
  • make your own smart buzzer using esphome
  • if you are not usually playing music while your doorbell rings, ditch the snapshoting and see how quick the sonos is. Just live with the interruption.
1 Like

Thank you both @Dolores and @WallyR for your contribution! Really appreciate it!

I managed to get the responstime down by removing the delay and moving most of it to “Scripts”.
Furthermore, I added “unjoin” (best practice) but not sure that contributed to a speedier process :slight_smile:

Here is what I ended up with:

doorbell:
  alias: "Sonos doorbell script"
  sequence:
   - service: sonos.snapshot
     data_template:
       entity_id: "{{ sonos_entity }}"
   - service: sonos.unjoin
     data_template:
       entity_id: "{{ sonos_entity }}"
   - service: media_player.volume_set
     data_template:
       entity_id: "{{ sonos_entity }}"
       volume_level: "{{ volume }}"
   - service: media_player.play_media
     data:
       entity_id: "{{ sonos_entity }}"
       media_content_id: http://192.168.1.48:8123/local/Ringklokke01.mp3
       media_content_type: music
   - delay: "{{ delay }}"
   - service: media_player.volume_set
     data_template:
       entity_id: "{{ sonos_entity }}"
       volume_level: 0.15
   - service: sonos.restore
     data_template:
       entity_id: "{{ sonos_entity }}"
1 Like

Really!!! I am shocked that it improved it much but I am not a software developer. If you had just offloaded the snapshot I would be less surprised. How fast would you guess that it is now? Thank you for following up. You should flag your post as the solution. :grin:

Actually, @Dolores, I’m shocked too! :slight_smile:
I also added the “unjoin” but not sure that helped speeding the process, though! :wink:

I accidently managed to short-circuit the battery before I could check the actual improvement in seconds (mother in-law pushed the button SO hard it got stuck, resulting in me disassembling the thing and unfortunately the wires popped out of the socket and touched! :roll_eyes:

I will revert once the new battery arrives :wink:

Sounds like not opening the door when mother-in-laws push the door bell is not the solution for you. :smiley: :smiley:

Hi @Dolores and @WallyR - you are absolutely right, better open that door straight away next time :smiley:

I finally got a new button and everything works flawlessly now! With music already playing on the Sonos speakers that are used for playing the Ding Dong ringtone, it now takes only 1 sec from the button push to Sonos actually playing the mp3.

Once again, thanks for your contribution! Really appreciate it! :pray: