Anyone have a suggestion for a device that works with #HomeAssistant that will play white noise?
-
Anyone have a suggestion for a device that works with #HomeAssistant that will play white noise?
My kiddo sleeps through _any_ noise in the evening but the slightest sound in the morning wakes him up. I'd like to ramp up volume at say, 4am then ramp it down when it's his waking time.
Needs to be super simple, no buttons, no mic, preferably no indicator lights. I've seen some DIY examples but off-the-shelf is better.
-
replied to Kyle Davis last edited by [email protected]
Nearly a month to the day, I've come up with a solution, built mostly out of things I already had. Basically, I generate white noise and control the volume of the noise with MQTT via #HomeAssistant
Hardware:
1) Raspberry Pi Zero W + microSD card
2) Cheap USB speaker (the only purchase: 16 CAD / 11 USD)
3) An old iPad charger
4) Various USB cords/adapters
5) An old cardboard boxSoftware:
1) Raspberry Pi OS Lite
2) Sound eXchange (SoX)
3) Mosquitto MQTT Client package
4) Home Assistant
1/7 -
replied to Kyle Davis last edited by [email protected]
Generate the white noise:
I found a great topic on AskUbuntu which showed how to use SoX to generate a nice ocean wave sound.
Generate white noise to calm a baby
I have a three week old baby. Occasionally she refuses to sleep. Some people tell me this is the way life is, some people tell me I need to buy things to fix it. This is becoming an alarmingly common
Ask Ubuntu (askubuntu.com)
I thought this was going to be the hard part, but it turned out to be quite easy.
2/7
-
replied to Kyle Davis last edited by [email protected]
Making it controllable:
I didn't want to bring in much for this since it is inherently a simple thing. I have MQTT in my Home Assistant setup and I was tempted to write Python, but I knew it could be simpler. Turns out, you can do this in a good old Bash script with a few lines.
To keep things simple my payload is just volume as number 0-99 - no JSON, YAML, etc. to parse.
3/7
-
replied to Kyle Davis last edited by [email protected]
Here is the slightly redacted script:
```
while read topic
do
if [[ $topic =~ ^[0-9]+$ ]]; then
volume_value=$(($topic))if (( $volume_value > -1)) && (( $volume_value < 100)); then
amixer -q -M sset PCM $volume_value%
fi
fi
done < <(mosquitto_sub -h somehost.local -t whitenoise/volume)
```Basically, just ensure that we have a valid volume number then pass that to `amixer` to set the main volume.
4/7
-
replied to Kyle Davis last edited by
Troubleshooting:
I had more problems with the Pi than anything else. First, I had some boot loop problems, turns out that was due to my particular USB power supply AND my micro USB cable. Then I had intermittent connectivity issues which were caused by the pi going into WiFi power save (why is that the default?).
5/7
-
replied to Kyle Davis last edited by
Putting it all together in `/etc/rc.local`:
```
#!/bin/bash# fix the wifi sleeping issues
/sbin/iwconfig wlan0 power off
# start playing the sound
/usr/bin/play -v 2 -q -n synth brownnoise synth pinknoise mix synth sine amod 0.3 10 gain -20 &
# Read from MQTT
/home/mclinuxface/white_noise.sh &
```At this point running `mosquitto_pub -h somehost.local -t whitenoise/volume -m '50'` would put the volume at 50%. Yay!
6/7
-
replied to Kyle Davis last edited by
Now in #HomeAssistant, I have a helper that renders as slider and an automation that looks like this:
```
- id: 'xxxx'
alias: White noise vol change
description: ''
trigger:
- platform: state
entity_id:
- input_number.white_noise_volume
condition: []
action:
- service: mqtt.publish
data:
topic: whitenoise/volume
payload: '{{ states(''input_number.white_noise_volume'') | int }}'
mode: single
```
7/7 -
L [email protected] shared this topic
-
replied to Kyle Davis last edited by
@linux_mclinuxface I think data centers are brown noise. That or pink. Could be wrong. Love that hum.
-
replied to Gabriel Moreno :verified: last edited by
@osb I’ve never been in a data center!