Skip to content

Extend local weather station override beyond temperature - #20

Closed
angst911 wants to merge 1 commit into
zach7036:mainfrom
angst911:ha-local-weather-station
Closed

angst911 wants to merge 1 commit into
zach7036:mainfrom
angst911:ha-local-weather-station

Conversation

@angst911

@angst911 angst911 commented Sep 2, 2026 •

Copy link
Copy Markdown

Summary

HA_TEMP_ENTITY (from #17) is great for overriding temperature from a local Home Assistant sensor, but most weather-station integrations (WeatherFlow/Tempest, Ecowitt, AccuWeather, etc.) actually expose a bundled weather.* entity with wind speed/bearing and a condition string, not just a raw temperature sensor. This adds an optional HA_WEATHER_ENTITY setting so wind speed, wind direction, sky condition, and day/night can also come from your own station, independently of and alongside HA_TEMP_ENTITY.

  • fetch_ha_weather() reads wind_speed/wind_bearing attributes and maps the entity's state (condition string) to the closest WMO code via a small lookup table. Conditions with no clean WMO equivalent (e.g. windy) are left alone rather than guessed at, so you still get a partial override (wind, no condition) instead of a wrong one.
  • fetch_ha_is_day() reads sun.sun for day/night, since weather.* entities don't expose that directly and it's a stock entity on every HA install.
  • Staleness is judged against last_updated rather than last_changed — a weather entity's condition can sit unchanged for hours on a clear day while its numeric attributes keep updating every few minutes, so last_changed would make the override look stale almost immediately.
  • Same fallback philosophy as the existing temperature override: any failure (unconfigured, unreachable, stale, unmapped condition) falls back to Open-Meteo silently, per-field.
  • Settings UI: added a "Weather entity" field next to the existing "Temperature entity" field under the renamed "Local weather station" section, same optional/blank-to-disable UX.

Test plan

  • pytest tests/test_weather_switch.py — 10 passed, including new coverage for the happy path, staleness fallback, unmapped-condition partial result, and the sun.sun day/night mapping
  • php -l scripts/config.php — no syntax errors
  • bash -n scripts/install_config.sh — no syntax errors
  • python3 -m py_compile scripts/utils/weather.py — compiles clean
  • Live-tested against a real WeatherFlow/Tempest weather.* entity on a running BirdNET-Pi install: ran weather.py manually with HA_WEATHER_ENTITY set, confirmed the log output and the resulting weather table row for the current hour matched the station's live reading exactly (temp, wind speed/direction, condition code, day/night)

🤖 Generated with Claude Code

HA_TEMP_ENTITY (added in #17) only overrides the current hour's
temperature from a Home Assistant sensor. Most weather-station
integrations (WeatherFlow/Tempest, Ecowitt, AccuWeather, etc.) expose a
bundled weather.* entity with wind speed/bearing and a condition
string, not just a raw temperature sensor - this adds an optional
HA_WEATHER_ENTITY setting that overrides wind speed, wind direction,
sky condition, and day/night from that entity, independently of and
alongside HA_TEMP_ENTITY.

- weather.py: fetch_ha_weather() reads wind_speed/wind_bearing
  attributes and maps the entity's condition string to the closest WMO
  code via a small lookup table; unmapped conditions (e.g. "windy")
  leave ConditionCode on the online value rather than guessing.
  fetch_ha_is_day() reads sun.sun for day/night, since weather.*
  entities don't expose that directly. Staleness is judged against
  last_updated rather than last_changed, since a weather entity's
  condition (state) can sit unchanged for hours while its attributes
  keep updating - last_changed would make the override look stale
  almost immediately.
- config.php / install_config.sh: expose HA_WEATHER_ENTITY next to the
  existing HA_TEMP_ENTITY field, same optional/blank-to-disable UX.
- tests: cover the new fetch functions (happy path, staleness
  fallback, unmapped-condition partial result, sun.sun mapping).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@zach7036

zach7036 commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Thanks for putting this together and testing it with your WeatherFlow/Tempest setup! Expanding Home Assistant support beyond a dedicated temperature sensor was a useful suggestion.

This functionality is now available in v2.7.0 — Local Weather Stations through a separate implementation. An optional weather.* entity can supply temperature, wind speed, wind direction, and supported sky conditions, while the existing dedicated temperature sensor remains supported.

The implementation includes unit conversion, reporting-timestamp freshness checks, and independent fallback to available online data for each field. Local observations are saved before requesting online weather and stored separately so subsequent online syncs don’t overwrite them. Station Doctor also provides diagnostics for the configured sources.

There are two intentional differences from this proposal: day/night continues using the existing station-location-based source rather than sun.sun, and local condition mappings cover clear, partly cloudy, cloudy, and fog. Broader precipitation descriptions retain available online conditions rather than assuming a specific intensity or type.

Thanks again for the contribution! Please try the release with your station and let me know if you encounter any integration-specific issues.

@zach7036 zach7036 closed this Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants