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

46 lines
1008 B
Bash
Executable File

#!/bin/bash
# see https://www.weatherapi.com
#AQHOME_TOOL="./aqhome-tool.sh"
AQHOME_TOOL="/usr/local/bin/aqhome-tool"
POS_CITY="$1"
POS_LAT="$2"
POS_LONG="$3"
API_KEY="$4"
if test -z "$POS_CITY"; then
echo "Usage: $0 CITY LATITUDE LONGITUDE APIKEY"
exit 1;
fi
if test -z "$POS_LAT"; then
echo "Usage: $0 CITY LATITUDE LONGITUDE APIKEY"
exit 1;
fi
if test -z "$POS_LONG"; then
echo "Usage: $0 CITY LATITUDE LONGITUDE APIKEY"
exit 1;
fi
if test -z "$API_KEY"; then
echo "Usage: $0 CITY LATITUDE LONGITUDE APIKEY"
exit 1;
fi
JSONFILE="/tmp/weather-oweathermap-$POS_CITY.json"
#
# get current weather
#
if ( curl -s -S "https://api.openweathermap.org/data/2.5/weather?lat=$POS_LAT&lon=$POS_LONG&appid=$API_KEY&units=metric" -o $JSONFILE ); then
$AQHOME_TOOL adddata -J $JSONFILE -c weather -d "openweathermap/$POS_CITY" -N "Temperature" -v "@main/temp" -U "C"
$AQHOME_TOOL adddata -J $JSONFILE -c weather -d "openweathermap/$POS_CITY" -N "Humidity" -v "@main/humidity" -U "%"
fi