Files
aqhomecontrol/scripts/getweather-openmeteo.sh
2026-08-24 23:36:25 +02:00

40 lines
990 B
Bash

#!/bin/bash
# see https://open-meteo.com/en/docs/dwd-api
#AQHOME_TOOL="./aqhome-tool.sh"
AQHOME_TOOL="/usr/local/bin/aqhome-tool"
POS_CITY="$1"
POS_LAT="$2"
POS_LONG="$3"
if test -z "$POS_CITY"; then
echo "Usage: $0 CITY LATITUDE LONGITUDE"
exit 1;
fi
if test -z "$POS_LAT"; then
echo "Usage: $0 CITY LATITUDE LONGITUDE"
exit 1;
fi
if test -z "$POS_LONG"; then
echo "Usage: $0 CITY LATITUDE LONGITUDE"
exit 1;
fi
JSONFILE="/tmp/weather-openmeteo-$POS_CITY.json"
#
# get current weather
#
if ( curl -s -S "https://api.open-meteo.com/v1/dwd-icon?latitude=$POS_LAT&longitude=$POS_LONG&current=temperature_2m,relative_humidity_2m" -o $JSONFILE ); then
$AQHOME_TOOL adddata -J $JSONFILE -c weather -d "open-meto/$POS_CITY" -N "Temperature" -v "@current/temperature_2m" -U "@current_units/temperature_2m"
$AQHOME_TOOL adddata -J $JSONFILE -c weather -d "open-meto/$POS_CITY" -N "Humidity" -v "@current/relative_humidity_2m" -U "@current_units/relative_humidity_2m"
fi