Guest User

ambientsounds-HA

a guest
Oct 10th, 2018
2,258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 5.08 KB | None | 0 0
  1. # RESOURCES:
  2.   # Credit to /u/dsgraham on Reddit - https://www.reddit.com/r/homeassistant/comments/9n0llr/google_ambient_sound_urls/
  3.   # Script adapted from Bob_NL on Home Assistant Forums - https://community.home-assistant.io/t/chromecast-radio-with-station-and-player-selection/12732
  4.   # Google webpage: https://support.google.com/googlehome/answer/7364558?hl=en
  5.  
  6. ###### CUSTOMIZE ----------------------------------------
  7.  
  8. homeassistant:
  9.   customize:
  10.     script.ambientsounds:
  11.       icon: mdi:play
  12.       friendly_name: Start Playing
  13.  
  14. ###### GROUPS ----------------------------------------
  15.  
  16. group:
  17.  Ambient Sounds:
  18.   name: Ambient Sounds
  19.   entities:
  20.  - input_select.ambient_sound
  21.   - input_select.google_home
  22.   - script.ambientsounds
  23.   - input_number.volume_ambientsounds
  24.  
  25. ###### INPUT SELECT ------------------------------------------
  26.  
  27. input_select:
  28.   ambient_sound:
  29.     name: 'Select Radio Station:'
  30.     options:
  31.      - Babbling brook sounds
  32.       - Oscillating fan sounds
  33.       - Fireplace sounds
  34.       - Forest sounds
  35.       - Country night sounds
  36.       - Ocean sounds
  37.       - Rain sounds
  38.       - River sounds
  39.       - Thunderstorm sounds
  40.       - White noise
  41.      
  42.   google_home:
  43.     name: 'Select Speakers:'
  44.     options:
  45.      - Livingroom
  46.       - Bedroom
  47.       - Kitchen
  48.       - Everywhere
  49.     initial: Everywhere
  50.     icon: mdi:speaker-wireless
  51.  
  52. ###### INPUT NUMBER ------------------------------------------
  53.  
  54. input_number:
  55.   volume_ambientsounds:
  56.     name: Volume
  57.     icon: mdi:volume-high
  58.     min: 0
  59.     max: 1
  60.     step: 0.05
  61.  
  62. ###### SCRIPTS ------------------------------------------
  63.    
  64. script:
  65.   ambientsounds:
  66.     alias: Play Ambient Sounds
  67.     sequence:
  68.       - service: media_player.volume_set
  69.         data:
  70.           entity_id: media_player.bedroom_speaker
  71.           volume_level: '0.35'
  72.       -  service: media_player.volume_set
  73.          data:
  74.            entity_id: media_player.kitchen_speaker
  75.            volume_level: '0.20'
  76.       -  service: media_player.volume_set
  77.          data:
  78.            entity_id: media_player.google_home
  79.            volume_level: '0.30'
  80.       -  service: media_player.play_media
  81.          data_template:
  82.            entity_id: >
  83.            {% if is_state("input_select.google_home", "Livingroom") %} media_player.google_home
  84.             {% elif is_state("input_select.google_home", "Bedroom") %} media_player.bedroom_speaker
  85.             {% elif is_state("input_select.google_home", "Kitchen") %} media_player.kitchen_speaker
  86.             {% elif is_state("input_select.google_home", "Everywhere") %} media_player.home_group
  87.             {% endif %}
  88.            media_content_id: >
  89.            {% if is_state("input_select.ambient_sound", "Babbling brook sounds") %} https://www.gstatic.com/voice_delight/sounds/long/brook.mp3
  90.             {% elif is_state("input_select.ambient_sound", "Oscillating fan sounds") %} https://www.gstatic.com/voice_delight/sounds/long/oscillating_fan.mp3
  91.             {% elif is_state("input_select.ambient_sound", "Fireplace sounds") %} https://www.gstatic.com/voice_delight/sounds/long/fireplace.mp3
  92.             {% elif is_state("input_select.ambient_sound", "Forest sounds") %} https://www.gstatic.com/voice_delight/sounds/long/forest.mp3
  93.             {% elif is_state("input_select.ambient_sound", "Country night sounds") %} https://www.gstatic.com/voice_delight/sounds/long/country_night.mp3
  94.             {% elif is_state("input_select.ambient_sound", "Ocean sounds") %} https://www.gstatic.com/voice_delight/sounds/long/ocean.mp3
  95.             {% elif is_state("input_select.ambient_sound", "Rain sounds") %} https://www.gstatic.com/voice_delight/sounds/long/rain.mp3
  96.             {% elif is_state("input_select.ambient_sound", "River sounds") %} https://www.gstatic.com/voice_delight/sounds/long/river.mp3
  97.             {% elif is_state("input_select.ambient_sound", "Thunderstorm sounds") %} https://www.gstatic.com/voice_delight/sounds/long/thunder.mp3
  98.             {% elif is_state("input_select.ambient_sound", "White noise sounds") %} https://www.gstatic.com/voice_delight/sounds/long/pink_noise.mp3
  99.             {% endif %}
  100.            media_content_type: 'audio/mp4'
  101.            
  102. ###############################################################################
  103. #                               Automations
  104. ###############################################################################
  105.  
  106. automation:
  107.   - alias: 'Set Radio Volume'
  108.     trigger:
  109.       platform: state
  110.       entity_id: input_number.volume_ambientsounds
  111.     action:
  112.       service: media_player.volume_set
  113.       data_template:
  114.         entity_id: >
  115.          {% if is_state("input_select.ambient_sound", "Livingroom") %} media_player.google_home
  116.           {% elif is_state("input_select.ambient_sound", "Bedroom") %} media_player.bedroom_speaker
  117.           {% elif is_state("input_select.ambient_sound", "Kitchen") %} media_player.kitchen_speaker
  118.           {% elif is_state("input_select.ambient_sound", "Everywhere") %} media_player.home_group
  119.           {% endif %}
  120.         volume_level: '{{  states.input_number.volume_ambientsounds.state  }}'
Add Comment
Please, Sign In to add comment