How to get first 300 lines of weather.get_forecasts into prompt of a ChatGPT converation?

Hi all.

I am looking for a way to hand-over the hourly forecast information to ChatGPT.
When I run the service manually, I see the full hourly output for serveral days. I copied/pasted this into the ChatGPT prompt and gave it some hints how to “understand” the data. This works very nice and I get crisp weather feedback.

Now, how can I hand-over the first 300 lines (or the first 24 hours) into the prompt of ChatGPT automatically?

I was playing with a script, which stores the full get_forecasts output into a return variable.
Now wanted to feed this into a shell_command ( echo {input} | head -n 300 ), and store this truncated result in a helper variable.
It did not work out as I want, and I assume this is anyways not the smartest or most correct approach to do this.

What should I do here?

Thank you.

BR, Marcus

Not sure what this is supposed to look like but this is based on a sensor that is created by get_forecasts

1 Like

This is interesting, thanks a lot.
Can you elaborate where this input_text… is coming from? - Do I have to create this on my own?

For your question this is not important …it is just ‘a’ sensor (helper) that I use to store forecasts at 6 each morning to see how it changes during the day.
EDIT: you are not providing any data whatsoever, I just showed you how you can get data from a list into blocks using [x:y]

1 Like

Well, as I said: I like to get the forecast data into the prompt OpenAI Conversation agent. I do not stick to “my way” at all, I am just poking around to find a solution. Your ones looks indeed more promising.

What I have understood:

  • you have a helper sensor that is filled every day at 6am
  • based on this data, you show me how the [x:y] is working

How do you get the forecast data into the helper? – Is this defined in the configuration.yaml as a template sensor? – Not sure how the [x:y] could be applied when I do not have the forecast in a helper.

I got the impression that you were much further…
To create a sensor there are dozens of other post in this forum, no one seems to want to search

- trigger:
  - platform: state
    entity_id: yourweatherentity
  action:
    - service: weather.get_forecast
      data:
        type: daily
      target:
        entity_id: yourweatherentity
      response_variable: daily
  sensor:
    - name: Weather Forecast Daily
      unique_id: weather_forecast_daily
      state: "{{ now().isoformat() }}"
      attributes:
        forecast: "{{ daily.forecast }}"
1 Like

Apologies when I was leading to this impression, I consider myself a newbie who is lost in the complexity of the yaml syntax. (inline and not inline, with dash and without, …)
I tried your code, and this is not working for me. This is mostly the same code that I also see on the documentation for the wheather integration, which is also not working. Also replace the trigger to a time_pattern one to force the update every minute, but the sensor remains empty.

I will be a week out of town and need to come back to this later.

What I am wondering:
Is the weather information stored inside Home Assistant, or does the “get_forecasts” service fetch the information in this second from the internet?
Why is it required to have a sensor duplicate the data that is already available in Home Assistant, only to make it accessible?

You have a weather integration and that uses an action (fka service) to pull forecast data. Weather Cards use that action.
Now, if you need the data for other purposes then you need to pull the data yourselves, e.g. I pull this for use in Apexcharts who cannot work (fafaik) via actions. So i have 1 sensor with up-to-date fc and one at 6 to see how good the forecast is (for use in other areas).
Add your code and then we can have a lookbut I am really surprised that you cannot find answers from the (literllay) dozens of other posts on this topic

Maybe this is useful for you?

1 Like