name: HA sensor trend
tools: sys.exec, outdoor, time
Query the outdoor temperature sensor from the last two weeks from the time now
and using the CSV (space separated) output, summarise the trend.
---
name: outdoor
tools: sys.exec
args: date: start date in YYYY-MM-DD
#!/home/hendry/homeassistant/sensor.sh ${date}
---
name: time
tools: sys.exec
#!date
Running this with gptscript rendered the output:
OUTPUT:
The temperature trend over the last two weeks shows a gradual increase from an average of around 2°C to 3°C at the beginning of the period to reaching highs of around 10°C. This indicates a warming trend over the two-week period.
OpenAPI can analyse more sensor data / tokens, though that comes at a cost.
My sensor.sh script looks like:
#!/bin/bash
DATE=$(date --date="$1" +"%Y-%m-%d")
curl -s --header "Authorization: Bearer ${HA_TOKEN}" --header 'Content-Type: application/json' "http://home.prazefarm.co.uk:8123/api/history/period/${DATE}?filter_entity_id=sensor%2Elumi%5Flumi%5Fsens%5Ftemperature&minimal_response&end_time=$(date --iso-8601)" |
jq -r '.[].[] | "\(.state) \(.last_changed)"'
To get this to work you need a OPENAI_API_KEY and HA_TOKEN (Long-Lived Access Tokens) set as shell environment variables.
Tbh gptscript/OpenAI could build the query automatically if the docs where marked up somewhere as OpenAPI [1]