|
1 | 1 |
|
2 | 2 | audio_dac:
|
3 | 3 | - platform: pcm5122
|
| 4 | + id: line_out_dac |
4 | 5 | address: 0x4D
|
5 | 6 | - platform: tas2780
|
| 7 | + id: speaker_dac |
6 | 8 | address: 0x3F
|
| 9 | + - platform: satellite1 |
| 10 | + id: dac_proxy |
| 11 | + speaker_dac: speaker_dac |
| 12 | + line_out_dac: line_out_dac |
| 13 | + |
| 14 | + on_speaker_activated: |
| 15 | + # if speaker was used previously but is not available try line-out |
| 16 | + - lambda: | |
| 17 | + if( id(line_out_sensor).state && id(pd_fusb302b).contract_voltage < 9 ){ |
| 18 | + id(dac_proxy).activate_line_out(); |
| 19 | + } |
| 20 | + |
| 21 | + on_line_out_activated: |
| 22 | + # if line_out was used previously but is not available try speaker |
| 23 | + - lambda: | |
| 24 | + if( !id(line_out_sensor).state && id(pd_fusb302b).contract_voltage >= 9 ){ |
| 25 | + id(dac_proxy).activate_speaker(); |
| 26 | + } |
| 27 | + |
| 28 | + on_state_change: |
| 29 | + - media_player.volume_set: |
| 30 | + volume: !lambda return id(dac_proxy).volume(); |
| 31 | + - lambda: | |
| 32 | + if( id(dac_proxy).is_muted() ){ |
| 33 | + id(nabu_media_player)->make_call() |
| 34 | + .set_command(MEDIA_PLAYER_COMMAND_MUTE) |
| 35 | + .perform(); |
| 36 | + } |
| 37 | + |
| 38 | +
|
| 39 | +binary_sensor: |
| 40 | + - platform: gpio |
| 41 | + id: line_out_sensor |
| 42 | + pin: |
| 43 | + pcm5122: |
| 44 | + pin: 4 |
| 45 | + inverted: false |
| 46 | + name: "line-out jack" |
| 47 | + icon: "mdi:audio-input-stereo-minijack" |
| 48 | + filters: |
| 49 | + - delayed_on: 200ms |
| 50 | + - delayed_off: 200ms |
| 51 | + |
| 52 | + on_press: |
| 53 | + - dac_proxy.activate_line_out: |
| 54 | + - lambda: id(jack_plugged_recently) = true; |
| 55 | + - script.execute: control_leds |
| 56 | + - delay: 200ms |
| 57 | + - script.execute: |
| 58 | + id: play_sound |
| 59 | + priority: false |
| 60 | + sound_file: !lambda return id(jack_connected_sound); |
| 61 | + - delay: 800ms |
| 62 | + - lambda: id(jack_plugged_recently) = false; |
| 63 | + - script.execute: control_leds |
| 64 | + |
| 65 | + |
| 66 | + on_release: |
| 67 | + - dac_proxy.activate_speaker: |
| 68 | + - lambda: id(jack_unplugged_recently) = true; |
| 69 | + - script.execute: control_leds |
| 70 | + - delay: 200ms |
| 71 | + - script.execute: |
| 72 | + id: play_sound |
| 73 | + priority: false |
| 74 | + sound_file: !lambda return id(jack_disconnected_sound); |
| 75 | + - delay: 800ms |
| 76 | + - lambda: id(jack_unplugged_recently) = false; |
| 77 | + - script.execute: control_leds |
| 78 | + |
7 | 79 |
|
8 | 80 | fusb302b:
|
9 | 81 | id: pd_fusb302b
|
@@ -44,9 +116,10 @@ media_player:
|
44 | 116 | sample_rate: 48000
|
45 | 117 | internal: false
|
46 | 118 | speaker:
|
| 119 | + audio_dac: dac_proxy |
47 | 120 | volume_increment: 0.05
|
48 |
| - volume_min: 0.4 |
49 |
| - volume_max: 0.85 |
| 121 | + volume_min: 0.1 |
| 122 | + volume_max: 1. |
50 | 123 | on_mute:
|
51 | 124 | - script.execute: control_leds
|
52 | 125 | on_unmute:
|
@@ -92,7 +165,10 @@ media_player:
|
92 | 165 | file: https://github.com/esphome/home-assistant-voice-pe/raw/dev/sounds/timer_finished.flac
|
93 | 166 | - id: wake_word_triggered_sound
|
94 | 167 | file: https://github.com/esphome/home-assistant-voice-pe/raw/dev/sounds/wake_word_triggered.flac
|
95 |
| - |
| 168 | + - id: jack_connected_sound |
| 169 | + file: https://github.com/esphome/home-assistant-voice-pe/raw/dev/sounds/jack_connected.flac |
| 170 | + - id: jack_disconnected_sound |
| 171 | + file: https://github.com/esphome/home-assistant-voice-pe/raw/dev/sounds/jack_disconnected.flac |
96 | 172 |
|
97 | 173 |
|
98 | 174 | script:
|
|
0 commit comments