New backup 2025-04-21 13:45:02
This commit is contained in:
parent
d463d572aa
commit
d1f84bd46e
1 changed files with 42 additions and 27 deletions
|
@ -2,20 +2,23 @@
|
|||
|
||||
hass_weather_cache="${HOME}/.cache/hass_weather.json"
|
||||
|
||||
if [[ ! $(find "${hass_weather_cache}" -cmin -60 -print 2>/dev/null) ]]; then
|
||||
if ! ping -w 15 -c 5 hass.pogmom.me;then
|
||||
exit
|
||||
fi
|
||||
|
||||
condition="$(jq -r '.current_condition[0].weatherDesc[0].value' ${hass_weather_cache})"
|
||||
condition_code="$(jq -r '.current_condition[0].weatherCode' ${hass_weather_cache})"
|
||||
current_temp="$(jq -r '.current_condition[0].temp_F' ${hass_weather_cache})"
|
||||
feels_temp="$(jq -r '.current_condition[0].FeelsLikeF' ${hass_weather_cache})"
|
||||
min_temp="$(jq -r '.weather[0].mintempF' ${hass_weather_cache})"
|
||||
max_temp="$(jq -r '.weather[0].maxtempF' ${hass_weather_cache})"
|
||||
humidity="$(jq -r '.current_condition[0].humidity' ${hass_weather_cache})"
|
||||
updated="$(date -r ${hass_weather_cache} '+%Y-%m-%d, %H:%M')"
|
||||
|
||||
update_cache_json(){
|
||||
# condition="$(jq -r '.current_condition[0].weatherDesc[0].value' ${hass_weather_cache})"
|
||||
condition="$(hass-cli -a states -e sensor.openweathermap_weather | jq -r '.state')"
|
||||
# condition_code="$(jq -r '.current_condition[0].weatherCode' ${hass_weather_cache})"
|
||||
condition_code="$(hass-cli -a states -e sensor.openweathermap_weather | jq -r '.state')"
|
||||
# current_temp="$(jq -r '.current_condition[0].temp_F' ${hass_weather_cache})"
|
||||
current_temp="$(hass-cli -a states -e sensor.openweathermap_temperature | jq -r '.state')"
|
||||
# feels_temp="$(jq -r '.current_condition[0].FeelsLikeF' ${hass_weather_cache})"
|
||||
feels_temp="$(hass-cli -a states -e sensor.openweathermap_feels_like_temperature | jq -r '.state')"
|
||||
# min_temp="$(jq -r '.weather[0].mintempF' ${hass_weather_cache})"
|
||||
min_temp="$(hass-cli -a states -e sensor.eugene_weather_realfeel_temperature_min_day_0 | jq -r '.state')"
|
||||
# max_temp="$(jq -r '.weather[0].maxtempF' ${hass_weather_cache})"
|
||||
max_temp="$(hass-cli -a states -e sensor.eugene_weather_realfeel_temperature_max_day_0 | jq -r '.state')"
|
||||
# humidity="$(jq -r '.current_condition[0].humidity' ${hass_weather_cache})"
|
||||
humidity="$(hass-cli -a states -e sensor.openweathermap_humidity | jq -r '.state')"
|
||||
# updated="$(date -r ${hass_weather_cache} '+%Y-%m-%d, %H:%M')"
|
||||
updated="$(date '+%Y-%m-%d, %H:%M')"
|
||||
|
||||
jq -n \
|
||||
--arg condition "${condition}" \
|
||||
|
@ -26,22 +29,34 @@ if [[ ! $(find "${hass_weather_cache}" -cmin -60 -print 2>/dev/null) ]]; then
|
|||
--arg humidity "${humidity}" \
|
||||
--arg icon "${condition_icon}" \
|
||||
--arg updated "${updated}" \
|
||||
'{condition: $condition,current_temp: $current_temp,feels_temp: $feels_temp,min_temp: $min_temp,max_temp: $max_temp,humidity: $humidity,icon: $icon,updated: $updated}'
|
||||
'{condition: $condition,current_temp: $current_temp,feels_temp: $feels_temp,min_temp: $min_temp,max_temp: $max_temp,humidity: $humidity,icon: $icon,updated: $updated}' \
|
||||
| tee "${hass_weather_cache}"
|
||||
|
||||
}
|
||||
|
||||
if [[ ! $(find "${hass_weather_cache}" -cmin -60 -print 2>/dev/null) ]]; then
|
||||
# if ! ping -w 15 -c 5 hass.pogmom.me;then
|
||||
# exit 1
|
||||
# fi
|
||||
|
||||
update_cache_json
|
||||
|
||||
# hass_weather_json=$(hass-cli)
|
||||
if [ "" != "${hass_weather_json}" ]; then
|
||||
echo "${hass_weather_json}" | tee "${hass_weather_cache}"
|
||||
fi
|
||||
# if [ "" != "${hass_weather_json}" ]; then
|
||||
echo "${hass_weather_json}" | tee "${hass_weather_cache}"
|
||||
# fi
|
||||
else
|
||||
cat "${hass_weather_cache}"
|
||||
fi
|
||||
|
||||
condition="$(jq -r '.current_condition[0].weatherDesc[0].value' ${hass_weather_cache})"
|
||||
condition_code="$(jq -r '.current_condition[0].weatherCode' ${hass_weather_cache})"
|
||||
current_temp="$(jq -r '.current_condition[0].temp_F' ${hass_weather_cache})"
|
||||
feels_temp="$(jq -r '.current_condition[0].FeelsLikeF' ${hass_weather_cache})"
|
||||
min_temp="$(jq -r '.weather[0].mintempF' ${hass_weather_cache})"
|
||||
max_temp="$(jq -r '.weather[0].maxtempF' ${hass_weather_cache})"
|
||||
humidity="$(jq -r '.current_condition[0].humidity' ${hass_weather_cache})"
|
||||
updated="$(date -r ${hass_weather_cache} '+%Y-%m-%d, %H:%M')"
|
||||
#condition="$(jq -r '.current_condition[0].weatherDesc[0].value' ${hass_weather_cache})"
|
||||
#condition_code="$(jq -r '.current_condition[0].weatherCode' ${hass_weather_cache})"
|
||||
#current_temp="$(jq -r '.current_condition[0].temp_F' ${hass_weather_cache})"
|
||||
#feels_temp="$(jq -r '.current_condition[0].FeelsLikeF' ${hass_weather_cache})"
|
||||
#min_temp="$(jq -r '.weather[0].mintempF' ${hass_weather_cache})"
|
||||
#max_temp="$(jq -r '.weather[0].maxtempF' ${hass_weather_cache})"
|
||||
#humidity="$(jq -r '.current_condition[0].humidity' ${hass_weather_cache})"
|
||||
#updated="$(date -r ${hass_weather_cache} '+%Y-%m-%d, %H:%M')"
|
||||
|
||||
case "${condition_code}" in
|
||||
113)
|
||||
|
@ -64,4 +79,4 @@ case "${condition_code}" in
|
|||
;;
|
||||
esac
|
||||
|
||||
jq -n --arg condition "${condition}" --arg current_temp "${current_temp}" --arg feels_temp "${feels_temp}" --arg min_temp "${min_temp}" --arg max_temp "${max_temp}" --arg humidity "${humidity}" --arg icon "${condition_icon}" --arg updated "${updated}" '{condition: $condition,current_temp: $current_temp,feels_temp: $feels_temp,min_temp: $min_temp,max_temp: $max_temp,humidity: $humidity,icon: $icon,updated: $updated}'
|
||||
#jq -n --arg condition "${condition}" --arg current_temp "${current_temp}" --arg feels_temp "${feels_temp}" --arg min_temp "${min_temp}" --arg max_temp "${max_temp}" --arg humidity "${humidity}" --arg icon "${condition_icon}" --arg updated "${updated}" '{condition: $condition,current_temp: $current_temp,feels_temp: $feels_temp,min_temp: $min_temp,max_temp: $max_temp,humidity: $humidity,icon: $icon,updated: $updated}'
|
||||
|
|
Loading…
Add table
Reference in a new issue