Hi
I am using an ESP for a small Model Kit and want to make it controllable within HomeAssistant.
Now, the basics are working fine - I do have my Lights which can be turned on and off from HomeAssistant and also via a physical “touch interface”…
Now, I want to extend this a bit - but yet, I haven’t really figured out, how this could be implemented:
- HA should provide a button
- This button should only be available, if the Lights are on
- When the button is pressed, the lights should enter a random / flickering sequence for a couple of time → and then, turn off.
Based on an example I found when I did some experiments with my S3 Box and Voice Assistant, I THINK, that should be acheivable with scripts … ?
At least, in this example, whenever the wakeword was detected and the device entered the “listening mode”, the display started to flash as long as the device was listening.
So I think, that could be a start for getting the configuration done - but I am not able to change the configuration accordingly to my requirements.
Here’s the example code:
# this is when the wake-word switch is turned off ... then you can use the top-left button to activate listening
- platform: gpio
pin:
number: GPIO0
mode: INPUT_PULLUP
inverted: true
name: Top Left Button
disabled_by_default: true
on_click:
- if:
condition:
switch.is_off: use_wake_word
then:
- if:
condition: voice_assistant.is_running
then:
- voice_assistant.stop:
- script.execute: reset_led
else:
- voice_assistant.start:
else:
- voice_assistant.stop
- delay: 1s
- script.execute: reset_led
- script.wait: reset_led
- voice_assistant.start_continuous:
output:
- platform: ledc
pin: GPIO45
id: backlight_output
light:
- platform: monochromatic
output: backlight_output
name: LCD Backlight
id: backlight
restore_mode: ALWAYS_ON
disabled_by_default: true
default_transition_length: 0s
effects:
- pulse:
transition_length: 250ms
update_interval: 250ms
- pulse:
name: Fast Pulse
transition_length: 50ms
update_interval: 50ms
voice_assistant:
id: va
microphone: box_mic
speaker: box_speaker
use_wake_word: true
noise_suppression_level: 2
auto_gain: 31dBFS
volume_multiplier: 2.0
vad_threshold: 3
on_listening:
- light.turn_on:
id: backlight
brightness: 100%
effect: pulse
on_tts_start:
- light.turn_on:
id: backlight
brightness: 75%
effect: pulse
on_end:
- delay: 100ms
- wait_until:
not:
speaker.is_playing:
- script.execute: reset_led
on_error:
- light.turn_on:
id: backlight
brightness: 50%
effect: fast_pulse
- delay: 1s
- script.execute: reset_led
- script.wait: reset_led
- lambda: |-
if (code == "wake-provider-missing" || code == "wake-engine-missing") {
id(use_wake_word).turn_off();
}
script:
- id: reset_led
then:
- if:
condition:
switch.is_on: use_wake_word
then:
- light.turn_on:
id: backlight
brightness: 25%
effect: none
else:
- light.turn_off: backlight
switch:
- platform: template
name: Use wake word
id: use_wake_word
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
entity_category: config
on_turn_on:
- lambda: id(va).set_use_wake_word(true);
- if:
condition:
not:
- voice_assistant.is_running
then:
- voice_assistant.start_continuous
- script.execute: reset_led
on_turn_off:
- voice_assistant.stop
- lambda: id(va).set_use_wake_word(false);
- script.execute: reset_led
Maybe, someone from the more experienced users here can help me with this?
Thanks in advance