Podcast then rain sound automation

Hi Everyone,

I like to listen to a podcast when I go to bed then have rain sounds to block out any ambient noise.

I have setup an input_text that takes the podcast URL.
I trigger the automation with a button.
The podcast is then streamed though a google home. I have a wait in my automation that waits for the speaker to go idle it then plays the rain sounds.

It seems to work pretty well but I am sure it could be improved. I am looking for any ideas :slight_smile:

How about showing us what you have done so far

NOTE please format you code

I want to see your wait logic
trying to get my head around that logic

Hi StePhan,

I have a main automation:

   trigger:
     - platform: event
       event_type: deconz_event
       event_data:
         id: bedroom_door
         event: 1005
     - platform: event
       event_type: deconz_event
       event_data:
         id: adams_switch
         event: 1005
   condition:
     condition: or
     conditions:
      - condition: state
        entity_id: media_player.roomy
        state: 'idle'
      - condition: state
        entity_id: media_player.roomy
        state: 'off'
   action:
     - service: script.play_podcast
     - delay: '00:00:04'
     - wait_template: "{{ states('media_player.roomy') != 'playing' }}"
       timeout: "00:59:00"
     - service: script.play_rain

The above automation runs the following 2 scripts:

play_podcast:
  sequence:
    - service: homeassistant.turn_off
      entity_id: media_player.roomy
    - service: media_player.volume_set
      data_template:
       entity_id: media_player.roomy
       volume_level: 0
    - delay: '00:00:02'
    - service: media_player.play_media
      data_template:
        entity_id: media_player.roomy
        media_content_id: "{{ states('input_text.podcast_to_play') }}"
        media_content_type: 'mp3'
    - service: media_player.volume_set
      data_template:
       entity_id: media_player.roomy
       volume_level: '{{  states.input_number.volume_podcast.state  }}' 
        
play_rain:
 sequence:
   - service: homeassistant.turn_off
     entity_id: media_player.roomy
   - service: media_player.volume_set
     data_template:
       entity_id: media_player.roomy
       volume_level: 0
   - delay: '00:00:02'
   - service: media_player.play_media
     data_template:
      entity_id: media_player.roomy
      media_content_id: http://192.168.1.33:8123/local/sounds/rainme.mp3   
      media_content_type: 'mp3'
   - service: media_player.volume_set
     data_template:
       entity_id: media_player.roomy
       volume_level: '{{  states.input_number.volume_rain.state  }}' 

I added some extra calls like this to reduce the notification sounds the google homes make when casting media:

   - service: media_player.volume_set
     data_template:
       entity_id: media_player.roomy
       volume_level: 0
2 Likes

Very slick, thanks for sharing!
Iโ€™ve been looking to do something similar, but I havenโ€™t found a good way to loop the MP3 so it runs all night. Any ideas?

I have a 12 hour mp3 :slight_smile:

Hah! Good idea :slight_smile: