#Automation not running rest script

1 messages · Page 1 of 1 (latest)

cold gale
#

Hi HA experts,

Im having a little issue with an automation that I don't understand because I don't have enough knowledge yet so I hope you can help me.

I have made a rest command:

  ollama_weather_report:
    url: "http://xxx.xxx.xxx.xxx:11434/api/generate"
    method: post
    headers:
      content-type: "application/json"
    payload: '{ "model": "llama3.2:latest",
        "prompt": "Generate a fun text for this weather predecition Max temperature tomorrow: 6 °C, Min temperature tomorrow: 2 °C, Precipitation tomorrow: 50%",
        "stream": false
      }'```

And an automation that calls it:

alias: Generate Weather Report
description: ""
triggers:

  • trigger: time_pattern
    hours: "*"
    minutes: /5
    seconds: "0"
    conditions: []
    actions:
  • action: rest_command.ollama_weather_report
    data: {}
  • delay: 2
  • target:
    entity_id: input_text.weather_report
    data:
    value: "{{ states('sensor.weather_report_output') }}"
    action: input_text.set_value
    mode: single

When the automation runs this is the trace result:

Executed: March 16, 2025 at 10:35:03 AM
Result:
params:
domain: input_text
service: set_value
service_data:
value: unknown
entity_id:
- input_text.weather_report
target:
entity_id:
- input_text.weather_report
running_script: false


As I see it the script isn't run, but I don't understand why, if run the script from the dev tools I get a resonse. So I'm hoping someone can help me troubleshoot this issue.
granite breach
#

What is the state of sensor.weather_report_output in Dev Tools > States?

#

How are you setting the value of that sensor?

cold gale
#

There is no state for weather_report_output

#

So I created an extra helper with that name, but that doesn't help

granite breach
#

Yup that's your problem. The helper is not being populated with any output from your rest command.

#

When you run the command from Dev Tools > Actions, what is the output? I suppose it produces a response variable?

cold gale
#

This is the response:

content:
  model: llama3.2:latest
  created_at: "2025-03-16T11:52:51.920883738Z"
  response: >-
    "Get ready for a chilly day ahead! Tomorrow's forecast is looking frosty
    with a max of just 6°C and a min of a refreshing 2°C. Don't forget your
    scarf and gloves, because it's going to feel like winter has arrived! And if
    that wasn't enough, there's a 50% chance of precipitation, so be prepared
    for a potentially soggy commute. But hey, at least the sun will come out
    again soon... right? Stay warm and cozy!"
  done: true
  done_reason: stop
  context:
    - 128006
    - 9125
    - 128007
  total_duration: 2615735373
  load_duration: 1660284616
  prompt_eval_count: 61
  prompt_eval_duration: 89000000
  eval_count: 101
  eval_duration: 861000000
status: 200
lament bolt
#

your not doing anything with the responce in the action when your calling it

#

you are missing
response_variable: weather_responce
then you use weather_responce in whatever you do with it

cold gale
#

I'm trying to understand what you are saying. Do you mean in the automation?

lament bolt
#

try this

description: ""
triggers:
  - trigger: time_pattern
    hours: "*"
    minutes: /5
    seconds: "0"
conditions: []
actions:
  - action: rest_command.ollama_weather_report
    response_variable: weather_responce    
  - delay: 2
  - target:
      entity_id: input_text.weather_report
    data:
      value: "{{ weather_responce }}"
    action: input_text.set_value
mode: single
#

that should run the command pull the result and store it then wait 2 seconds then put the stored value into input_text.weather_report

#

assuming input_text.weather_report exists

cold gale
#

that works

lament bolt
#

cool, do you see what the problem was?

cold gale
#

but the helpers don't get updated yet

lament bolt
#

input_text.weather_report isnt updating?

cold gale
#

one sec, let me double check all names

#

I have these 2:

lament bolt
#

weather_report_output is not currently being used so thats not relivent

cold gale
#

I didn't have a text helper for weather_responce I created it and ran it again but it's still not updated

lament bolt
#

can try this in the automation

description: ""
triggers:
  - trigger: time_pattern
    hours: "*"
    minutes: /5
    seconds: "0"
conditions: []
actions:
  - action: rest_command.ollama_weather_report
    response_variable: weather_responce    
  - delay: 2
  - target:
      entity_id: input_text.weather_report
    data:
      value: "{{ weather_responce.content.response }}"
    action: input_text.set_value
mode: single```
#

realised its probably trying to set the whole object instead of just the responce part

granite breach
#

Yup and the response length cannot exceed 255 chars.

cold gale
#

that is an issue. The response is way way longer 😆

#

I think double

granite breach
#

What are you doing with the response after storing it in the input text?

#

Wondering whether you can just pipe the response directly to whatever you have in mind, and skip setting it into the input text's state.

cold gale
#

I want to show it on a dashboard for checking in the morning. But I now limited it to 200 characters

cold gale
granite breach
#

One way around the 255 character state limit is to store it as an attribute of an entity, not a state.

#

But take it one step at a time. Can you handle the response text now?

cold gale
#

I ran the last automation @lament bolt sent and it shows this:

cold gale
lament bolt
#

an input_text helper != variable

cold gale
#

Okay, so it's doing what it should? but I want it to write to a helper so I can use it other parts of HA. or is that not needed?

lament bolt
#

from what i can see it should be setting the input_text.weather_report helper with the responce

granite breach
#

Check the state of the input text in Dev Tools > States to confirm.

cold gale
#

I'm a dumdum. It works. The size of the weather_report helper wasn't big enough. it was still on the standaard 100 chars. I changed it to 200 and now it got filled.

Now my next step is to figure out how to send variables to the REST script

#

if you have some tips on how to please send me to the correct docs I'll start to try and experiment

granite breach
#

From the docs, several fields are marked template so you can use Jinja to pass variables to those fields dynamically. Just like how @lament bolt used Jinja to pass the response to the input text's set value action.

cold gale
#

Okay, I'll try to work on it. I think I might understand it now

#

one last question, the max response lengthe of 255 is that a hard limit?

granite breach
#

Use Dev Tools > Template to iterate the Jinja till it provides the correct value.

cold gale
#

thanks for the tip

granite breach
lament bolt
#

i havent actually used it but isnt there a ollama integration? or is that specifically for being an assist option?

cold gale
#

and there it works about as good as I expect for my setup

lament bolt
#

you can set it up as an assist option then call it with conversation.process

cold gale
#

okay, that is something new to read for me 🙂

lament bolt
#

might end up being easier then using rest commands

#

generating the payload for the rest command will be awkward as shit