Skip to content

Instantly share code, notes, and snippets.

@darnmason
Last active February 22, 2025 05:35
Show Gist options
  • Save darnmason/f1cc12da02f4f64551ad007914d83326 to your computer and use it in GitHub Desktop.
Save darnmason/f1cc12da02f4f64551ad007914d83326 to your computer and use it in GitHub Desktop.
A Home Assistant Blueprint to control volume and looping of a white noise track on a media player
blueprint:
name: White Noise
description: Control speaker volume and repeat settings for a white noise track.
domain: automation
input:
media_player:
name: Media Player
description: The speaker where the white noise track will be played.
selector:
entity:
filter:
- domain: media_player
device_class: speaker
media_title:
name: White Noise Track
description: The title of the white noise track.
selector:
text:
type: text
starting_volume:
name: Starting Volume
description: The media player volume when the white noise starts playing.
selector:
number:
min: 0
max: 1
step: 0.01
mode: slider
lower_volume:
name: Lower Volume
description: The media player volume while white noise plays after the configured time.
selector:
number:
min: 0
max: 1
step: 0.01
mode: slider
default_volume:
name: Default Volume
description: The expected media player volume when white noise is not playing.
selector:
number:
min: 0
max: 1
step: 0.01
mode: slider
lower_volume_time:
name: Lower Volume Time
description: The time to lower the volume if the white noise is still playing.
selector:
time:
working_days_off_time:
name: Off Time (Working days)
description: The time to stop the white noise on working days, good for morning.
selector:
time:
all_days_off_time:
name: Off Time (All days)
description: The time to stop the white noise on any day, good for nap cut-offs.
selector:
time:
triggers:
- trigger: state
entity_id:
- !input media_player
attribute: media_title
to: !input media_title
id: "started"
- trigger: state
entity_id:
- !input media_player
attribute: media_title
from: !input media_title
id: "stopped"
- trigger: time
at: !input working_days_off_time
id: "off_working"
- trigger: time
at: !input all_days_off_time
id: "off_all"
- trigger: time
at: !input lower_volume_time
id: "lower"
conditions: []
actions:
- choose:
- conditions:
- condition: trigger
id: "started"
sequence:
- action: media_player.repeat_set
data:
repeat: "one"
target:
entity_id: !input media_player
- action: media_player.volume_set
data:
volume_level: !input starting_volume
target:
entity_id: !input media_player
- conditions:
- condition: trigger
id: "stopped"
sequence:
- action: media_player.repeat_set
data:
repeat: "off"
target:
entity_id: !input media_player
- action: media_player.volume_set
data:
volume_level: !input default_volume
target:
entity_id: !input media_player
- conditions:
- condition: trigger
id: "off_all"
- condition: state
entity_id: !input media_player
state: "playing"
- condition: state
entity_id: !input media_player
attribute: media_title
state: !input media_title
sequence:
- action: media_player.media_pause
data: {}
target:
entity_id: !input media_player
- conditions:
- condition: trigger
id: "off_working"
- condition: state
entity_id: binary_sensor.workday_sensor
state: "on"
- condition: state
entity_id: !input media_player
state: "playing"
- condition: state
entity_id: !input media_player
attribute: media_title
state: !input media_title
sequence:
- action: media_player.media_pause
data: {}
target:
entity_id: !input media_player
- conditions:
- condition: trigger
id: "lower"
- condition: state
entity_id: !input media_player
state: "playing"
- condition: numeric_state
entity_id: !input media_player
attribute: volume_level
above: !input lower_volume
sequence:
- action: media_player.volume_set
data:
volume_level: !input lower_volume
target:
entity_id: !input media_player
mode: queued
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment