Every time we watch TV we have to basically hold the remote in the hand because the volume varies so much.
I thought of an idea. Use a microphone to measure the sound coming out of the center speaker behind the TV and adjust the volume of my Yamaha receiver.
See it in action (with a volume up again after 1 second).
(high number means low volume on this receiver since it’s negative db scale)
I added a gy-max4466 microphone on a breadboard with a ESP8266.
Gave it 3.3 volts, ground and connected the output of the microphone to A0.
With ESPHome you can use the ADC sensor to measure the voltage coming out of the speaker and have it react to values above a threshold like this:
sensor:
- platform: adc
pin: A0
name: "Sound"
update_interval: 0.2s
internal: true
on_value_range:
- above: 0.72
then:
- switch.turn_on: snd
- below: 0.30 # You must have below: but by setting it below the normal baseline it's deactivated.
then:
I use a GPIO switch in the board because I had problems getting it to work when publishing the values to HA and have an automation run.
ESPHome switch:
switch:
- platform: gpio
pin: D3 # unused pin, just to make sure it's visible in HA.
name: "snd"
id: snd
Now this switch can be used as a trigger in an automation:
This automation runs a script that sets a new volume and turns off the GPIO switch.
- id: '1586697299820'
alias: Skruva ner
description: ''
trigger:
- entity_id: switch.snd
platform: state
to: 'on'
condition: []
action:
- data: {}
service: script.1586684255359
- data: {}
entity_id: switch.snd
service: switch.turn_off
Where the script is:
'1586684255359':
alias: New Script
sequence:
- service: media_player.volume_set
data_template:
entity_id: media_player.yamaha_receiver
volume_level: >
{{ states.media_player.yamaha_receiver.attributes.volume_level - 0.10 }}
Yamaha receivers can be controlled within HA with volume up/down or set.
This script uses the current volume and lowers it by 10%.
This can most likely be edited to change the volume of a TV either with API or with a broadlink.
It works beautifully!
You don’t even notice the high sound before it’s already lowered.
But I have thought of some improvements already.
I have two problems. One is soon one year old and the other is soon four years old.
If you also have something like that, they will trigger it to lower the volume since the microphone can’t distinguish TV from kids.
But I will look in to hooking up the ESP directly to the output of the receiver. I will measure what the voltage is on the speaker cables or look at other ways.