Skip to content

ras434/noisyPi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

noisyPi

Raspberry Pi noise generator integration with Home Assistant using MQTT.

Maintenance GitHub stars


Requirements

  • Raspberry Pi
  • Home Assistant (https://www.home-assistant.io/)
    • MQTT Broker (Mosquitto)
    • MQTT account (to authenticate with NoisyPi)
    • NoisyPi entities in configuration.yaml file
      • switch.noisypi - turn on/off
      • input_value.noisypi - set volume
      • input_select.noisypi - select noise color [whitenoise, pinknoise, brownnoise]
    • Automations
      • volume publish & subscribe MQTT
      • noise color publish & subscribe MQTT

Installation

Steps

  1. Install Python3
  2. Install SoX - Sound eXchange
  3. Install paho-mqtt
  4. Edit /etc/rc.local
  5. Clone noisyPi.py
  6. Setup Home Assistant
  7. Add noisyPi card to Home Assistant
  8. Reboot Your Raspberry Pi

1. Python3 Install Python3

From the Raspberry Pi:

  sudo apt update
  sudo apt install python3

2. Install SoX - Sound eXchange

From the Raspberry Pi:

  apt-get install sox

3. Install paho-mqtt

From the Raspberry Pi:

  pip install paho-mqtt

4. Edit /etc/rc.local

From the Raspberry Pi:

Using nano or vi edit /etc/rc.local.

nano example:

  sudo nano /etc/rc.local

Paste the following lines to the end of the file.
CTRL+X to exit, y to save, and ENTER to accept file.

  # Run noisyPi setup
  amixer sset 'Headphone' 95%
  python3 /home/pi/noisyPi/noisyPi.py
  exit 0

5. Clone noisyPi.py

From the Raspberry Pi:

  mkdir ~/noisyPi
  cd ~/noisyPi
  wget https://raw.githubusercontent.com/ras434/noisyPi/main/noisyPi.py

6. Setup Home Assistant

From Home Assistant configuration.yaml file, add the following entries:

  input_number:
    noisypi_volume:
      name: NoisyPi volume
      initital: 80
      min: 50
      max: 95
      step: 1
      icon: mdi:volume-high

  input_select:
    noisypi_noise_color:
      name: NoisyPi Noise Color
      options:
        - whitenoise
        - pinknoise
        - brownnoise
      initial: brownnoise
      icon: mdi:palette
  
  switch:
    - platform: mqtt
      name: "noisyPi"
      icon: mdi:speaker
      state_topic: "stat/noisypi/NOISE"
      command_topic: "cmnd/noisypi/NOISE"
      availability_topic: "tele/noisypi/LWT"
      payload_on: "on"
      payload_off: "off"
      state_on: "on"
      state_off: "off"
      qos: q
      retain: false

From Configuration > Automations, add the following 4 new automations:


NoisyPi Color (pub):

alias: NoisyPi Color (pub)
description: NoisyPi Color Selection Changed
trigger:
  - platform: state
    entity_id: input_select.noisypi_noise_color
condition: []
action:
  - service: mqtt.publish
    data:
      topic: cmnd/noisypi/COLOR
      retain: true
      qos: '1'
      payload: '{{ states(''input_select.noisypi_noise_color'') }}'
mode: single

NoisyPi Color (sub):

alias: NoisyPi Color (sub)
description: Set NoisyPi Color Value
trigger:
  - platform: mqtt
    topic: stat/noisypi/COLOR
condition: []
action:
  - service: input_select.set_value
    target:
      entity_id: input_select.noisypi_color
    data:
      value: '{{ trigger.payload }}'
mode: single

NoisyPi Volume (pub):

alias: NoisyPi Volume (pub)
description: NoisyPi Volume Slider Moved
trigger:
  - platform: state
    entity_id: input_number.noisypi_volume
condition: []
action:
  - service: mqtt.publish
    data:
      topic: cmnd/noisypi/VOLUME
      retain: true
      qos: '1'
      payload: '{{ states(''input_number.noisypi_volume'') | int }}'
mode: single

NoisyPi Volume (sub):

alias: NoisyPi Volume (sub)
description: Set NoisyPi Volume Slider
trigger:
  - platform: mqtt
    topic: stat/noisypi/VOLUME
condition: []
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.noisypi_volume
    data:
      value: '{{ trigger.payload }}'
mode: single

7. Add noisyPi Card to Home Assistant

From Home Assistant: In your Lovelace UI, edit your preferred dashboard and add the noisyPi elements: card

8. Reboot Your Raspberry Pi:

From Raspberry Pi:

sudo reboot

Once your Pi completes the reboot it should automatically start noisypi.py.

About

Raspberry Pi noise generator integration with Home Assistant using MQTT

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published