Skip to content
 
 

Repository files navigation

Buy Me A Coffee

Home assistant support for Opendata CWA (prvious Opendata CWB). The readme in Traditional Chinese.

This integration is based on OpenWeatherMap (@csparpa, pyowm) to develop.

Install

You can install component with HACS custom repo: HACS > Integrations > 3 dots (upper top corner) > Custom repositories > URL: tsunglung/OpenCWB > Category: Integration

Or manually copy opencwb folder to custom_components folder in your config folder.

Then restart HA.

Latest changes

v1.5.0

  • Model one OpenCWA config entry as a farm/location with any number of native Home Assistant crop subentries.
  • Add, edit, and remove crop records independently. Each crop keeps its own growth stage, planting date, area, warnings, notification, and irrigation-reference entities.
  • Fetch city crop weather, catalog, and warning rules once per farm update, then build isolated per-crop snapshots. Stable subentry IDs prevent entity churn when crops are renamed or reordered.
  • Existing 1.4.x single-crop settings migrate losslessly to the first crop subentry.

v1.4.1

  • Change the crop-name field to a searchable dropdown containing 127 official 高雄農來訊 crop names, while retaining custom entry for newly added or uncommon crops.
  • Rendering the form does not contact the agricultural provider; agriculture remains disabled by default and failure-isolated.

v1.4.0

  • Add a fully optional nationwide agricultural guidance provider backed by 高雄農來訊: crop warnings/advisories, support status, notification payloads, and token-gated ET0/Kc/ETc/water-requirement references.
  • The provider is disabled by default and failure-isolated. Missing configuration, timeout, authentication failure, malformed/stale data, or an unsupported crop never prevents CWA weather, forecasts, or official warnings from loading.
  • Keep CWA and agricultural attribution separate. Missing agricultural data is never presented as a safe condition.

v1.3.43

  • Parse the CWA REST API dataset/records/record response shape as independent alert records, restoring each alert's official issue time, validity period, description, wind level, and expiry handling in Home Assistant.

v1.3.42

  • Preserve each CWA hazardous-weather dataset's own issue time, validity window, and official description instead of mixing metadata across simultaneous alerts.
  • For land strong-wind advisories, show the official yellow/orange/red level, average-wind and gust Beaufort thresholds, equivalent lower-bound speeds, validity period, danger explanation, and actionable crop/greenhouse risk guidance.
  • Agricultural impacts are explicitly labelled as threshold-based guidance, not an official CWA crop-loss forecast.

v1.3.41

  • Alert only when the CWA track approaches Taiwan, may affect the configured coordinates, and an official CWA typhoon warning is active; otherwise expose monitoring without recommending a push notification.
  • Expose closest-distance, closest-approach-time, and risk-decision attributes for explainable dashboards and automations.
  • Display unnamed systems using their CWA tropical-depression number, such as Unnamed tropical depression TD12, instead of Unknown ().

v1.3.40

  • Fix hazardous-weather notifications mixing the title and affected areas of an unmatched alert with aggregate location matches from other alerts.
  • When multiple alerts match the configured location, include every matched alert in the notification and omit unrelated alerts.

v1.3.39

  • Add three ready-to-use notification sensors for official typhoon warnings, tropical cyclone pre-alerts, and hazardous weather alerts.
  • Notification sensor attributes expose title, message, severity, summary, and source_dataset so automations can call notify.* without complex templates.

v1.3.38

  • Improve hazardous-weather alert location matching for CWA special areas such as 恆春半島, 蘭嶼綠島, 基隆北海岸, and county mountain-area labels.
  • Add matched_locations, unmatched_special_areas, and match_method attributes to weather alert sensors.
  • Add parser regression tests for expired typhoon warnings, multiple tropical cyclones, missing track values, and special-area alert matching.
  • Document optional CWA warning entities and automation examples.

v1.3.37

  • When an optional warning group is disabled in the integration options, remove its stale Home Assistant entities from the entity registry and current states.

v1.3.36

  • Add optional CWA official typhoon warning, tropical cyclone track, and hazardous weather alert entities.
  • New integration options: official typhoon warning, tropical cyclone track, and hazardous weather alerts.

v1.3.34

  • Fix onecall_daily startup failure.
  • Root cause: the current / UV one-call request was incorrectly sent to F-D0047-093, which returns 404 Resource not found for the lon/lat/locationName/interval request shape.
  • Switch back to F-D0047-091 for one-call current / UV; daily forecast still comes from the existing legacy district-level forecast path.
  • This keeps onecall_daily working without losing district-level forecast granularity.

v1.3.13

  • Fix onecall_* UV index lookup for township / district locations such as 新店區.
  • Keep the configured location name unchanged in Home Assistant.
  • Internally upgrade district names to their parent city only for onecall current / UV requests.
  • Keep forecast sensors on the original district-level forecast source, so UV works without sacrificing local forecast granularity.
  • Verified live: UV index restored while forecast sensors remain normal.

v1.3.11 - v1.3.12

  • Restore forecast sensors that were stuck at unknown after the forecast model refactor.
  • Make forecast sensor extraction compatible with both native and serialized Forecast field names.
  • Remove invalid hourly templow handling.

v1.3.6

  • Fix the update button so it no longer depends on a non-existent coordinator attribute.
  • The button now records its own status fields in attributes:
    • update_status
    • last_update_time
    • previous_update_time
    • last_error (only when refresh fails)
  • Keep the button grouped under the same device as the weather/sensor entities.

v1.3.1 - v1.3.5

  • Improve Home Assistant Weather Entity compatibility.
  • Return proper Forecast objects for daily / hourly forecast.
  • Add native weather properties such as UV index and precipitation.
  • Add an update button entity for immediate weather refresh.
  • Fix older Home Assistant import compatibility issues.

Optional 高雄農來訊 agricultural guidance

Enable KCG agricultural guidance from Settings > Devices & services > OpenCWA > Configure. When disabled, OpenCWA does not construct the provider client/coordinator or make agricultural HTTP requests.

The main OpenCWA entry represents the farm/location and stores the shared enable switch and password-masked provider token. Use the native Add crop action on the OpenCWA integration page to add as many crop records, planting batches, or fields as needed. Every crop record independently stores its searchable crop name, growth stage, planting date, and cultivation area. Crop records can be edited or removed without changing other crop entities.

Each crop creates an independent agriculture device with warning, advisory, support, notification, ET0, Kc, ETc, and water-requirement entities. Entity identity uses the stable Home Assistant crop subentry ID rather than the editable crop name or list order.

The token is only required for ET0, Kc, ETc, and water-requirement endpoints; crop warnings and support checks remain tokenless. City crop weather, catalog, and warning rules are downloaded once per farm update and then filtered locally for every configured crop. Provider or parser failure for one crop never stops CWA coordinators or replaces another crop's valid snapshot.

If a legacy area value is invalid, OpenCWA creates a visible crop record and retains the original value as recovery metadata; edit that crop once to repair it. In Options, leave the token field blank to keep the stored token, or check Clear stored agricultural token to remove it.

Agricultural guidance is attributed to 高雄農來訊; weather remains attributed to CWA. OpenCWA-derived guidance is not an official CWA crop-loss forecast, and no data/unsupported/stale/unavailable never means safe.

Optional CWA warning entities

OpenCWA can optionally create dedicated CWA warning entities. They are disabled by default to avoid extra API calls for existing users.

Enable them from Settings > Devices & services > OpenCWA > Configure:

  • Enable official typhoon warning (enable_typhoon_warning): uses CWA W-C0034-001 CAP data to identify an official Taiwan typhoon warning. Tropical-cyclone track data alone is not treated as an official warning.
  • Enable tropical cyclone track (enable_tropical_cyclone_track): uses CWA W-C0034-005 for active tropical cyclone track/fix data.
  • Enable hazardous weather alerts (enable_weather_alerts): uses CWA hazardous-weather warnings and matches affected areas against the configured location and its parent city when available.

Created entities, using 安平區 as an example location:

Entity Meaning
binary_sensor.opencwa_an_ping_qu_typhoon_warning on only when an official typhoon warning is currently active. Cancel, END, expired CAP messages, and解除 notices are off.
sensor.opencwa_an_ping_qu_typhoon_warning_status Typhoon warning status and CAP attributes such as headline, report number, warning type, affected areas, effective/expires, and typhoon position.
sensor.opencwa_an_ping_qu_typhoon_warning_notification Ready-to-use official typhoon warning notification payload. Attributes include title, message, severity, and summary.
sensor.opencwa_an_ping_qu_tropical_cyclone Number of active tropical cyclones; attributes include latest fix, analysis fixes, forecast fixes, wind speed, pressure, and storm radius data.
sensor.opencwa_an_ping_qu_tropical_cyclone_notification Ready-to-use tropical cyclone pre-alert payload. State becomes suppressed when an official typhoon warning is already active.
binary_sensor.opencwa_an_ping_qu_weather_alert on when a hazardous-weather alert matches the configured location.
sensor.opencwa_an_ping_qu_weather_alerts Count and details for hazardous-weather alerts. Attributes include matched_locations, unmatched_special_areas, and match_method.
sensor.opencwa_an_ping_qu_weather_alert_notification Ready-to-use hazardous-weather alert notification payload with matched locations, special areas, and CWA text. Land strong-wind advisories also expose official warning level/thresholds plus clearly labelled crop and greenhouse risk guidance.

Special-area matching covers common CWA area labels such as 恆春半島, 蘭嶼綠島, 基隆北海岸, and county mountain-area labels such as 高雄山區. Generic labels such as 山區 or 沿海空曠地區 may be reported in unmatched_special_areas when they cannot be safely mapped to the configured location.

Example automation:

alias: Notify when CWA typhoon warning starts
trigger:
  - platform: state
    entity_id: binary_sensor.opencwa_an_ping_qu_typhoon_warning
    to: "on"
action:
  - service: notify.mobile_app_your_phone
    data:
      title: CWA Typhoon Warning
      message: >-
        {{ state_attr('binary_sensor.opencwa_an_ping_qu_typhoon_warning', 'headline') }}

Setup

Apply a API key in Opendata CWA

  1. Open the Opendata CWA Web Site
  2. Register your account
  3. Get your personal API Key.

Config

Please use the config flow of Home Assistant

  1. With GUI. Configuration > Integration > Add Integration > OpneCWA
    1. If the integration didn't show up in the list please REFRESH the page
    2. If the integration is still not in the list, you need to clear the browser cache.
  2. Enter API key.
  3. Enter the location name of Taiwan. Please reference to the name in the doc.
    1. Some location names need to include the city name.
    2. Township / district names are allowed, for example 新店區, 板橋區, 大安區.
    3. For ambiguous names such as 東區, 北區, 中山區, include the city name, for example 嘉義市東區 or 臺中市東區.
    4. In onecall_* modes, the integration keeps your configured township / district name in Home Assistant, but internally upgrades it to the parent city only for current / UV lookup when required by the CWA onecall dataset.
    5. Forecast data still stays on the original township / district source, so using onecall_* does not force you to give up local forecast granularity.

Buy Me A Coffee

LINE Pay LINE Bank JKao Pay
Line Pay Line Bank JKo Pay

About

Home Assistant for Opendata CWB. Get the weather forecast of the city in Taiwan.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages