Help with moving Python code value to Home Assistant

So I have this Python code that uses Accuweather api to get the predicted temperature 12 hours in advance. I want to move this value to Home Assistant to trigger a relay if certain conditions are met. I’ve made the python_scripts folder and the set up for it.

import requests
import json
import datetime
import pytz

# API key from AccuWeather Developer Portal
api_key = "redacted"

# Location key for the desired location
location_key = "326854"

def get_future_temp():

    global temp
    # Make API call to AccuWeather API
    response = requests.get(f"http://dataservice.accuweather.com/forecasts/v1/hourly/12hour/{location_key}?apikey={api_key}&metric=false")

    # Parse JSON response
    data = json.loads(response.text)

    # Extract the hourly temperatures and times for the next day
    next_day_temperatures = []
    next_day_times = []
    for forecast in data:
        time = datetime.datetime.fromisoformat(forecast["DateTime"].split("+")[0]).replace(tzinfo=pytz.UTC)
        if time >= datetime.datetime.now(pytz.UTC) and time <= datetime.datetime.now(pytz.UTC) + datetime.timedelta(days=1):
            next_day_times.append(time.strftime("%Y-%m-%d %H:%M:%S"))
            next_day_temperatures.append(forecast["Temperature"]["Value"])

    # Gets closes temperature and time to the next day
    temp = next_day_temperatures[-1]

    return(temp)

get_future_temp()

Is it possible to send this value to Home Assistant, if so how? I’m pretty new to HA.

You can use the command_line sensor. Just change your script to print out the value.
I don’t think your script will work in python_scripts.

It is not possible to use Python imports with this integration. If you want to do more advanced scripts, you can take a look at AppDaemon or pyscript

Ok gotcha I’ll look into it. Thanks for the help!