Added Mute logic (that does not fix newly introduced crashes).
This commit is contained in:
		| @@ -73,7 +73,7 @@ micro_wake_word: | ||||
| #    - model: alexa | ||||
| #  vad: | ||||
|   microphone: luxe_mic | ||||
|   on_wake_word_detected:         | ||||
|   on_wake_word_detected: | ||||
|     - voice_assistant.start: | ||||
|         wake_word: !lambda return wake_word; | ||||
|  | ||||
| @@ -113,13 +113,44 @@ output: | ||||
| globals: | ||||
|   - id: Vol | ||||
|     type: float | ||||
|     initial_value: '0.6'     | ||||
|     initial_value: '0.6' | ||||
|   - id: phase | ||||
|     type: int | ||||
|     initial_value: '0'     | ||||
|   - id: mute   | ||||
|     initial_value: '0' | ||||
|   - id: mute | ||||
|     type: bool | ||||
|     initial_value: 'false'         | ||||
|     initial_value: 'false' | ||||
|   - id: muteH | ||||
|     type: bool | ||||
|     initial_value: 'false' | ||||
|  | ||||
| interval: | ||||
|   - interval: 0.1sec | ||||
|     then: | ||||
|       - if: | ||||
|           condition: | ||||
|              - speaker.is_stopped: | ||||
|           then: | ||||
|              - if: | ||||
|                 condition: | ||||
|                   - not: | ||||
|                      - lambda: 'return(id(muteH));' | ||||
|                 then: | ||||
|                   - output.turn_on: dac_mute | ||||
|                   - lambda: id(muteH) = true; | ||||
|                   - logger.log: "====> hardware mute" | ||||
|  | ||||
|       - if: | ||||
|           condition: | ||||
|              - speaker.is_playing: | ||||
|           then: | ||||
|              - if: | ||||
|                 condition: | ||||
|                   - lambda: 'return(id(muteH));' | ||||
|                 then: | ||||
|                   - output.turn_off: dac_mute | ||||
|                   - lambda: id(muteH) = false; | ||||
|                   - logger.log: "====> hardware unmute" | ||||
|  | ||||
| sensor: | ||||
|   - platform: adc | ||||
| @@ -191,13 +222,13 @@ binary_sensor: | ||||
|         pullup: true | ||||
|     name: Volume Up | ||||
|     on_click: | ||||
|         - lambda: |-        | ||||
|         - lambda: |- | ||||
|                 id(Vol) += 0.05; | ||||
|                 if(id(Vol) > 1) id(Vol) = 1;             | ||||
|                 if(id(Vol) > 1) id(Vol) = 1; | ||||
|         - media_player.volume_set:  | ||||
|                 id: luxe_media_player         | ||||
|                 volume: !lambda return id(Vol);          | ||||
|           | ||||
|                 id: luxe_media_player | ||||
|                 volume: !lambda return id(Vol); | ||||
|  | ||||
|   - platform: gpio | ||||
|     pin: | ||||
|       number: GPIO32 | ||||
| @@ -207,13 +238,13 @@ binary_sensor: | ||||
|         pullup: true | ||||
|     name: Volume Down | ||||
|     on_click: | ||||
|         - lambda: |-        | ||||
|         - lambda: |- | ||||
|                 id(Vol) -= 0.05; | ||||
|                 if(id(Vol) < 0) id(Vol) = 0;             | ||||
|                 if(id(Vol) < 0) id(Vol) = 0; | ||||
|         - media_player.volume_set:  | ||||
|                 id: luxe_media_player         | ||||
|                 volume: !lambda return id(Vol);               | ||||
|        | ||||
|                 id: luxe_media_player | ||||
|                 volume: !lambda return id(Vol); | ||||
|  | ||||
|   - platform: gpio | ||||
|     pin: | ||||
|       number: GPIO12 | ||||
| @@ -222,16 +253,16 @@ binary_sensor: | ||||
|         input: true | ||||
|         pullup: true  | ||||
|     name: Mute | ||||
|     on_click:        | ||||
|     on_click: | ||||
|       - if: | ||||
|           condition: | ||||
|                - lambda: 'return(id(mute));'             | ||||
|                - lambda: 'return(id(mute));' | ||||
|           then: | ||||
|               - script.execute: mute_off | ||||
|               - lambda: id(mute) = false; | ||||
|           else: | ||||
|               - script.execute: mute_on | ||||
|               - lambda: id(mute) = true;   | ||||
|               - lambda: id(mute) = true; | ||||
|     on_double_click: | ||||
|        - if: | ||||
|            condition:  | ||||
| @@ -271,9 +302,9 @@ microphone: | ||||
|     sample_rate: 16000 | ||||
|     i2s_din_pin: GPIO35 | ||||
|     bits_per_sample: 16bit | ||||
|     channel: left | ||||
|     adc_type: external   | ||||
|      | ||||
|     channel: stereo | ||||
|     adc_type: external | ||||
|  | ||||
| speaker: | ||||
|   - platform: i2s_audio | ||||
|     id: luxe_speaker | ||||
| @@ -282,8 +313,8 @@ speaker: | ||||
|     sample_rate: 48000 | ||||
|     bits_per_sample: 16bit | ||||
|     channel: stereo | ||||
|     buffer_duration: 100ms      | ||||
|      | ||||
|     buffer_duration: 100ms | ||||
|  | ||||
| media_player: | ||||
|   - platform: speaker | ||||
|     name: None | ||||
| @@ -294,37 +325,36 @@ media_player: | ||||
|       speaker: luxe_speaker | ||||
|       format: FLAC | ||||
|       sample_rate: 48000 | ||||
|       num_channels: 2    | ||||
|       num_channels: 2 | ||||
|     files: | ||||
|       - id: little_sound | ||||
|         file: https://github.com/esphome/home-assistant-voice-pe/raw/dev/sounds/timer_finished.flac              | ||||
|         file: https://github.com/esphome/home-assistant-voice-pe/raw/dev/sounds/timer_finished.flac | ||||
|     on_announcement:  | ||||
|       - micro_wake_word.stop: | ||||
|       - if: | ||||
|            condition: | ||||
|                 lambda: 'return(id(phase) != 2);' | ||||
|            then:            | ||||
|            then: | ||||
|               - lambda: |- | ||||
|                    if(id(phase) == 1)  id(phase) = 2;     | ||||
|               - script.execute: mute_off          | ||||
|               - script.execute: update_led     | ||||
|                       | ||||
|                    if(id(phase) == 1)  id(phase) = 2; | ||||
|               - script.execute: mute_off | ||||
|               - script.execute: update_led | ||||
|  | ||||
|     on_idle: | ||||
|       - wait_until: | ||||
|          and: | ||||
|           - not: | ||||
|               media_player.is_announcing: | ||||
|           - not: | ||||
|               voice_assistant.is_running:     | ||||
|               voice_assistant.is_running: | ||||
|       - if: | ||||
|           condition:               | ||||
|           condition: | ||||
|               lambda: 'return((id(phase) == 4) || (id(phase) == 2));' | ||||
|           then: | ||||
|             - lambda: |- | ||||
|                  id(phase) = 1;  | ||||
|       - micro_wake_word.start:                                                 | ||||
|       - script.execute: update_led      | ||||
|        | ||||
|                  id(phase) = 1; | ||||
|       - micro_wake_word.start: | ||||
|       - script.execute: update_led | ||||
|  | ||||
| voice_assistant: | ||||
|   id: va | ||||
| @@ -336,10 +366,10 @@ voice_assistant: | ||||
|   volume_multiplier: 2.0 | ||||
|    | ||||
|   on_listening:  | ||||
|      - logger.log: "listening 3 => phase"                     | ||||
|      - logger.log: "listening 3 => phase" | ||||
|      - micro_wake_word.stop: | ||||
|      - lambda: |- | ||||
|         id(phase) = 3;                             | ||||
|         id(phase) = 3; | ||||
|      - script.execute: update_led | ||||
|  | ||||
|   on_stt_end: | ||||
| @@ -353,53 +383,53 @@ voice_assistant: | ||||
|        | ||||
|  | ||||
|   on_tts_start: | ||||
|      - logger.log: "answering  4 => phase"                    | ||||
|      - logger.log: "answering  4 => phase" | ||||
|      - lambda: |- | ||||
|         id(phase) = 4; | ||||
|      - script.execute: update_led | ||||
|                       | ||||
|  | ||||
|   on_error: | ||||
|     - logger.log: "ERROR!!!!!!!!!!!!!!!!"   | ||||
|     - logger.log: "ERROR!!!!!!!!!!!!!!!!" | ||||
|     - light.turn_on: | ||||
|         id: top_led | ||||
|         blue: 0% | ||||
|         red: 100% | ||||
|         green: 0% | ||||
|         effect: pulse           | ||||
|         effect: pulse | ||||
|     - delay: 3s | ||||
|     - lambda: id(phase) = 1;     | ||||
|     - script.execute: update_led  | ||||
|    | ||||
|  | ||||
|  | ||||
| ######### | ||||
| # Scripts | ||||
|  | ||||
| script:    | ||||
| script: | ||||
|   - id: update_led | ||||
|     then:   | ||||
|        - logger.log: "==>>>update_led"  | ||||
|        - logger.log: "==>>>update_led" | ||||
|        - lambda: |- | ||||
|              if(id(phase) == 0)id(start).execute(); | ||||
|              if(id(phase) == 1)id(waiting).execute();   | ||||
|              if(id(phase) == 2)id(external_player).execute();                       | ||||
|              if(id(phase) == 1)id(waiting).execute(); | ||||
|              if(id(phase) == 2)id(external_player).execute(); | ||||
|              if(id(phase) == 3)id(listening).execute(); | ||||
|              if(id(phase) == 4)id(answering).execute(); | ||||
|                           | ||||
|   - id: start            | ||||
|  | ||||
|   - id: start | ||||
|     then: | ||||
|      - light.turn_on: | ||||
|           id: top_led | ||||
|           effect: slow_pulse | ||||
|           red: 80% | ||||
|           green: 0% | ||||
|           blue: 80%              | ||||
|           blue: 80% | ||||
|      - delay: 5sec | ||||
|      - lambda: id(my_es8388).setup(); | ||||
|      - output.turn_off: dac_mute | ||||
|      - lambda: id(phase) = 1; | ||||
|      - media_player.speaker.play_on_device_media_file: | ||||
|           media_file: little_sound | ||||
|           announcement: true         | ||||
|           announcement: true | ||||
|      - script.execute: update_led | ||||
|       | ||||
|   - id: waiting | ||||
| @@ -411,8 +441,8 @@ script: | ||||
|           green: 0% | ||||
|           blue: 100%  | ||||
|           brightness: 100%  | ||||
|      - voice_assistant.stop:               | ||||
|      - micro_wake_word.start:                        | ||||
|      - voice_assistant.stop: | ||||
|      - micro_wake_word.start: | ||||
|         | ||||
|  | ||||
|   - id: listening | ||||
| @@ -422,8 +452,8 @@ script: | ||||
|           effect: pulse | ||||
|           red: 0% | ||||
|           green: 100% | ||||
|           blue: 0%                       | ||||
|           brightness: 100%        | ||||
|           blue: 0% | ||||
|           brightness: 100% | ||||
|            | ||||
|   - id: answering | ||||
|     then: | ||||
| @@ -432,8 +462,8 @@ script: | ||||
|           effect: none | ||||
|           red: 100% | ||||
|           green: 100% | ||||
|           blue: 0%                      | ||||
|           brightness: 100%        | ||||
|           blue: 0% | ||||
|           brightness: 100% | ||||
|            | ||||
|   - id: external_player | ||||
|     then: | ||||
| @@ -442,7 +472,7 @@ script: | ||||
|           effect: none | ||||
|           red: 80% | ||||
|           green: 40% | ||||
|           blue: 0%                       | ||||
|           blue: 0% | ||||
|               | ||||
|   - id: mute_on | ||||
|     then: | ||||
|   | ||||
		Reference in New Issue
	
	Block a user