Web Search through automations?

Is this something that can be done? I’ve set up a custom Google search and put a REST command in config.

rest_command:
  web_search:
    url: >
      https://www.googleapis.com/customsearch/v1?key=sssh&cx=secret&q={{ query }}
    method: get

And this url works in browser and returns a JSON as expected.

I have an automation for Voice Assistant:

alias: Voice Web Search
description: ""
triggers:
  - command:
      - search the web for {query}
      - look up {query}
      - search {query}
    trigger: conversation
actions:
  - response_variable: result
    action: rest_command.web_search
  - data:
      entity_id: media_player.wyoming_satellite_1184c0_media_player
      message: |
        {% if result.content.AbstractText %}
          {{ result.content.AbstractText }}
        {% else %}
          I couldn't find a clear answer.
        {% endif %}
    action: tts.speak

But whenever i search, even using just typing into Assist, I get an error while tracing the automation:

result:
  content:
    error:
      code: 400
      message: Request contains an invalid argument.
      errors:
        - message: Request contains an invalid argument.
          domain: global
          reason: badRequest
      status: INVALID_ARGUMENT

I can’t for the life of me figure out what I’m doing wrong or where to find the info to see the url it spits out.

What does the rest command action return when you run it from the Action tool?

You haven’t passed any variables to the rest command. You need to add data: followed by the variable name and the value. See here.

Well I’m trying different ways of doing that, but this YAML stuff is breaking me. The formatting makes no sense. I now have

actions:
  - response_variable: result
    action: rest_command.web_search
    data:
      query: "{{ trigger.slots.query }}"

but that doesn’t seem to pass the variable.

It’s best to build code in steps: verify one piece is working before adding complexity to it. In this case, get the action working with a hardcoded variable first, and then figure out how to pass a template into the variable.

That is what Didgeridrew was asking. Go to developer tools → actions, select your rest command, and switch to YAML mode. There you can add the variable, and use something hardcoded for now, and something that doesn’t need url-encoding so you can avoid that pitfall for now as well:

action: rest_command.web_search
data:
  query: weather
response_variable: result

If that works, then you can start adding complexity, like url encoding and then passing variables.

Regarding url encoding, since skip_url_encoding is set to false by default (per the docs), you probably don’t need your template to do that.

content:
  error:
    code: 404
    message: Requested entity was not found.
    errors:
      - message: Requested entity was not found.
        domain: global
        reason: notFound
    status: NOT_FOUND
status: 404
headers:
  Vary: Origin
  Content-Type: application/json; charset=UTF-8
  Content-Encoding: gzip
  Date: Sat, 10 Jan 2026 14:57:39 GMT
  Server: ESF
  X-XSS-Protection: "0"
  X-Frame-Options: SAMEORIGIN
  X-Content-Type-Options: nosniff
  Alt-Svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
  Transfer-Encoding: chunked

That is the response you’re getting from Google. I don’t know what that service is, so it’s difficult for me to help you with that part. HA is doing what you are telling it to do. If I run the command I get a 400 error because my credentials are made-up, or I get 403 when I exclude them entirely.

You might try to execute your query using CURL in a terminal window (rather than a browser), so that you verify exactly what needs to be sent.

1 Like

You got it, something was wrong with my custom search engine, the key they generated looked shorter than another key i had. So i used my older key and it worked. thanks!
Well, almost gotta fix my automation now.

1 Like

Update: It “works”. But Voice Assistant can’t parse the spoken query. I can type a search as a conversation and even hard code a voice query. But it seems that unless it’s written down, Voice Assistant (at least through a ReSpeaker satellite) can’t parse the query.

Any way this could be worked around? Obviously an LLM or HA Cloud are solutions, but you see Ollama barely runs on this old AMD thin client, I don’t have spare GPUs or money for such things and not interested in paying more subscriptions.