Local mp3 sound to Sonos after a triger

Hello,

I would like to play a local mp3 file on my Sonos after a trigger. does anyone know how I can set this to my home assist automation?

Hope to hear anything

Easy, in automations state which entity you want to trigger on.

Then in action field: Play local mp3 on Sonos error

1 Like

Hi dank voor je antwoord. Aangezien je profiel Nederlands aangeeft hier even mij vervolg vraag: ik probeer het in te vullen in de automatisering, maar krijg het niet voor elkaar om het werkend te krijgen.Is er een mogelijkheid dat je het uitlegt?

Because it’s an international community, we must obey the rules and write english. If you don’t understand this explanation then feel free to write me privately.

  1. Go to your automations page and create a new one
  2. Under trigger, choose the domain where the entity is which you want this automation to trigger on.

So for example, when a binary sensor (a door lock for example) triggers to ON. Obviously you can choose any entity here you want. So if you want to use any other entity, check what state you want it to trigger on. In this example I use binary_sensor.sensor_l_voordeur

So when someone opens my frontdoor (voordeur), the sensor goes from off to on. boom, thats when the automation is triggered.

  1. under action, you define you want to play a file to a media entity, i have a sonos too called woonkamer.

Note: you must have a folder named: www inside the root of your home assistant and reboot it once after creating. So the link ‘http://10.0.1.85:8123/local/Test.mp3’. local is actually your www folder.

Good luck!

2 Likes

Hello,

Thank you for helping! I understand why we should talk in English. I sent a pm

Here are two automations I have setup to speak the information using Sonos Play 1. First uses TTS to speak info about nearby fire department dispatches. And I also have my Sonos acting as a Cuckoo Clock, plays MP3 files, to your question. An ignominious place in the home for the Sonos after the Apple HomePods arrived… :grinning:

The Sonos is setup via Home Assistant Integrations. The first automation is called when a custom sensor I have sees a fire department dispatch on their web site that is within a geo fence of the house. The automation uses Nabu Casa text to speech services to create the message.

The second automation, the MP3 Cuckoo Clock, plays any MP3 file. It is driven by time trigger. The key things for the Sonos to play the MP3 files was to get the correct ‘service’ and ‘media_contect_type’, as shown below.

# automations.yaml

- alias: Close Event County Fire
  trigger:
    platform: template
    value_template: "{{  \n  is_state_attr('sensor.pulsepoint_sbco', 'close_to_key_location',\
      \ true) }}\n"
  action:

  - service: tts.cloud_say
    entity_id: media_player.living_room
    data:
      message: '"Pulsepoint notification close to {{ state_attr(''sensor.pulsepoint_sbco'',
        ''key_location'') }} , {{ state_attr(''sensor.pulsepoint_sbco'', ''desc_short'')
        }}"

        '
      language: en-US
      options:
        gender: female
  id: 5535435465645223


# automations.yaml


- alias: Cuckoo Clock
  trigger:
  - platform: time_pattern
    minutes: 0
    seconds: 5
  condition:
    condition: and
    conditions:
    - condition: time
      after: 06:00:00
      before: '22:31:00'
  action:
  - service: media_player.volume_set
    data:
      entity_id: media_player.living_room
      volume_level: 0.56
  - service: media_player.play_media
    data_template:
      media_content_id: '{% set b = now().strftime("%H") %} http://192.168.2.100:8123/local/sounds/cuckoo/cuckoo-clock-{{b}}.mp3

        '
      entity_id: media_player.living_room
      media_content_type: music
  id: 3242342389759835398

Hello,

Sorry, I’m new to this so this might be a dumb question.

I just installed a Unify G4 doorbell, and Home Automation detected it, but I don’t have a binary sensor for it. Do I have to create that manually? For a new automation, I select State and the doorbell entity is displayed as device_tracker.carport_doorbell. Can I just use that for the entity, or does it need to be a binary sensor?

Thanks!

Doesnt have to be. Does that tracker change state when doorbell is pressed? If so, you can make an automation that can trigger when state changes and play a doorbell sound

Does this directory still need to be created if I’m using Home Assistant supervised? I used Samba to add my mp3 to what I believe is the default media directory. Using this tip for locating the URL I get:

http://192.168.1.100:8123/media/local/airhorn.mp3

But no luck getting it to play on Sonos. I can see and play the mp3 in the Media Browser when I select Web Browser with the “Choose Player” option in the upper right hand corner.

If I try to go directly to that URL in my browser I get “401: Unauthorized” and when I open up my Sonos app I can see airhorn.mp3 listed as the thing most recently played but if I hit the play button I get “Unable to play ‘airhorn.mp3’ - access is denied.”

Have you tried to make a www folder under config and access the file from there?

Note: if theres no www folder under config, and you just created one, remember to restart home assistant for home assistant to understand to use www folder. Otherwise it wont work.

I think if you browse media directly, you have to provide credentials or access it through a token, but that’s not going to work for a sonos.

Others, feel free to correct me though xD