ESPHome Voice Assistant - Error handeling

In the online documentation for ESPHome Voice Assistant:

  • on_error (Optional, Automation): An automation to perform when the voice assistant has encountered an error. The error code and message are available to automations as the variables code and message.

But how do you actually catch this 'code and ‘message’ in code? I have tried:

  on_error:
    - logger.log:
        format: "Err.code: %f Msg: %s"
        args: [ 'id(va).code', 'id(va).message' ]

But the compiler doesn’t know what I’m talking about:

/config/esphome-web-c2fcc4.yaml:100:52: error: 'class esphome::voice_assistant::VoiceAssistant' has no member named 'code'
/config/esphome-web-c2fcc4.yaml:100:62: error: 'class esphome::voice_assistant::VoiceAssistant' has no member named 'message'

I am very new to YAML :blush:

I stumbled upon the solution myself. So this is the correct code:

    - logger.log:
        level: WARN
        format: "Err.code: %d Msg: %s"
        args: [ 'code', 'message' ]

But the result is not understandable to me. Below is examples of the error log from Voice Assistant. And several examples of the output from my logger script. And both code and message doesn’t really match up to the original. I know that the message result is hex for ascii codes. Which I haven’t tried to translate as there is only 2 or 3 letters anyway. Am I doing something wrong?

[E][voice_assistant:653]: Error: no_wake_word - No wake word detected
[W][main:709]: Err.code: 1073423644 Msg: p\xfd\xfd?
[W][main:709]: Err.code: 1073423644 Msg: \xc5\xfd?
[W][main:709]: Err.code: 1073423644 Msg:
[W][main:709]: Err.code: 1073423644 Msg: \xc8\xea\xfd?
[W][main:709]: Err.code: 1073423644 Msg: \xd4\xfb\xfd?

[E][voice_assistant:653]: Error: stt-no-text-recognized - No text ecognized
[W][main:709]: Err.code: 1073423644 Msg: @\xc9\xfd?
[W][main:709]: Err.code: 1073423644 Msg: \xf8\xc6\xfd?
[W][main:709]: Err.code: 1073423644 Msg: p\xc5\xfd?