#Using button entity in HA to start voice command

1 messages ยท Page 1 of 1 (latest)

stray badge
#

hi, the following should be pretty close to what you need. give it a shot and see if it works ๐Ÿ™ƒ

text_sensor:
  - platform: homeassistant
    id: zigbee_button
    name: zigbee
    entity_id: YOUR_ZIGBEE_BUTTON_ENTITY_ID
    internal: true
    on_value:
      - if:
          condition:
            - lambda: return id(zigbee_button).state == "on";
          then:     
            - lambda: id(va).set_use_wake_word(false);  
            - delay: 50ms
            - voice_assistant.stop:
            - wait_until:
                not:
                  - voice_assistant.is_running:
            - voice_assistant.start:
          else:
            - lambda: id(va).set_use_wake_word(true);  
            - delay: 50ms
            - voice_assistant.stop:
            - wait_until:
                not:
                  - voice_assistant.is_running:
            - voice_assistant.start_continuous: 
stray badge
#

after the else: wakeword will be active again... so if you didn't want this you can alter it to

          else:
            - voice_assistant.stop:

You would hold the button down during the period that you issue the command and release to end. (like a walkie talkie PTT)

haughty steeple
#

Hi BigBobba, thanks so much for your help, I'll give it a try later today ๐Ÿ™‚

stray badge
#

you're welcome. I've tested it myself and works well ๐Ÿ‘ but if you are using microwakeword, it would need a couple of bits changing

haughty steeple
#

Hi BigBobba, so I finally got a chance to play with it. It works... But there's a really long delay from once I've pressed my ZigBee button, to the voice assistant being activated (I'm talking like 5 minutes!). I know the ZigBee switch I'm using works, as I've been using it to turn on a smart plug. Do you have any idea what could be causing such a massive delay?

stray badge
#

if you view the ESPHome logs, whne you press the button is it showing in the logs straight away ?

haughty steeple
#

No, it doesn't seem to... I haven't been able to catch it so far, but also haven't been watching it for minutes. Would network setup have anything to do with it (not sure why as everything else works fine)? All my ESP devices run on a separate network to my HA instance.

stray badge
#

you could test with another entity.. such as a light and see what happens when you turn it on.. it should pretty much be instant. I don't have any zigbee devices to test with. I tested with a light and as soon as i switched the light on it started. Another thing to check would be the HA>>settings>>system>>logs to see if there is anything in there that may help diagnose

haughty steeple
#

Thanks for the tips. I just tried it on another satellite, which has less entities, and therefore less going on in the logs. I can see the following, but then Assist in progress is not activating. Maybe there's something else in my ESP config, which is causing it not to work? [20:18:31][D][homeassistant.text_sensor:017]: 'sensor.test_button_action': Got state 'single'
[20:18:31][D][text_sensor:064]: 'zigbee': Sending state 'single'
[20:18:31][D][homeassistant.text_sensor:017]: 'sensor.test_button_action': Got state ''
[20:18:31][D][text_sensor:064]: 'zigbee': Sending state ''
[20:18:31][D][voice_assistant:620]: Signaling stop...
[20:18:31][D][voice_assistant:504]: State changed from STREAMING_MICROPHONE to STOP_MICROPHONE
[20:18:31][D][voice_assistant:510]: Desired state set to IDLE
[20:18:31][D][voice_assistant:504]: State changed from STOP_MICROPHONE to STOPPING_MICROPHONE
[20:18:31][D][esp-idf:000]: I (100053) I2S: DMA queue destroyed

#

Sorry for the bad format...

#

OK, so it's something with the state from the zigbee button. I just tried with a light as you suggested, and it works straight away!

#

The difference I can see between using a light, and a zigbee button, is that the button shows two states, one straight after the other (firstly 'single' then ''). The light only shows one state. I tried using the state 'single', which didn't seem to work. I then tried '' (so just a blank state, no text), but then the assist in progress turns on straight away, and keeps cycling from on to off, then straight onto on again... Might have to consider using a light somehow...

stray badge
#

you could possibly create a boolean helper in HA that switches on with the button and use the state of the helper instead

haughty steeple
#

YES! great idea, I'll try that ๐Ÿ™‚

haughty steeple
#

Got it working with a toggle (input boolean), once playing around with a little automation linking the zigbee button to the toggle. Thanks again for your help, really appreciate people like yourself helping out us rookies ๐Ÿ™‚