Skip to main content

🌤️ Python Wrapper for WeatherFlow REST API

Latest PyPI version Supported Python

This module communicates with a WeatherFlow Weather Station using a their REST API.

The module is primarily written for the purpose of being used in Home Assistant for the Custom Integration called weatherflow but might be used for other purposes also.

When this is done, it will replace the previous module pysmartweatherio

Install

pyweatherflowrest is avaible on PyPi:

pip install pyweatherflowrest

Usage

This library is primarily designed to be used in an async context.

The main interface for the library is the pyweatherflowrest.WeatherFlowApiClient. This interface takes 6 options:

  • station_id: (required) Supply the station id for the station you want data for.
  • api_token: (required) Enter your personal api token for the above station id. You can get your Personal Use Token by going here and login with your credentials. Then click CREATE TOKEN in the upper right corner.
  • units: (optional) Valid options here are metric or imperial. WeatherFlow stations always deliver data in metric units, so conversion will only take place if if metric is not selected. Default value is metric
  • forecast_hours: (optional) Specify how many hours of the Hourly Forecast that needs to be retrieved. Values between 1 and 240 are valid. Default value is 48 hours.
  • homeassistant: (optional) Valid options are True or False. If set to True, there will be some unit types that will not be converted, as Home Assistant will take care of that. Default value is False
  • session: (optional) An existing aiohttp.ClientSession. Default value is None, and then a new ClientSession will be created.
import asyncio
import logging
import time

from pyweatherflowrest.api import WeatherFlowApiClient
from pyweatherflowrest.data import ObservationDescription, StationDescription, ForecastDescription, ForecastDailyDescription
from pyweatherflowrest.exceptions import WrongStationID, Invalid, NotAuthorized, BadRequest

_LOGGER = logging.getLogger(__name__)

async def main() -> None:
    logging.basicConfig(level=logging.DEBUG)
    start = time.time()

    weatherflow = WeatherFlowApiClient("YOUR STATION ID", "YOUR TOKEN")
    try:
        await weatherflow.initialize() # Must be the first call

    except WrongStationID as err:
        _LOGGER.debug(err)
    except Invalid as err:
        _LOGGER.debug(err)
    except NotAuthorized as err:
        _LOGGER.debug(err)
    except BadRequest as err:
        _LOGGER.debug(err)

    data: StationDescription = weatherflow.station_data
    if data is not None:
        for field in data.__dataclass_fields__:
            value = getattr(data, field)
            print(field,"-", value)

    data: ObservationDescription = await weatherflow.update_observations()
    if data is not None:
        for field in data.__dataclass_fields__:
            value = getattr(data, field)
            print(field,"-", value)


    data: ForecastDescription = await weatherflow.update_forecast()
    if data is not None:
        for field in data.__dataclass_fields__:
            value = getattr(data, field)
            if field == "forecast_daily":
                for item in value:
                    print(item.conditions, item.air_temp_high)
            elif field == "forecast_hourly":
                for item in value:
                    print(item.conditions, item.air_temperature)
            else:
                print(field,"-", value)

    end = time.time()

    await weatherflow.req.close()

    _LOGGER.info("Execution time: %s seconds", end - start)

asyncio.run(main())

Release files for pyweatherflowrest 1.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyweatherflowrest 1.0.11
File Size Uploaded
pyweatherflowrest-1.0.11.tar.gz 15.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyweatherflowrest 1.0.11
File Interpreter ABI Platform
pyweatherflowrest-1.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 30.0 kB

Release files / pyweatherflowrest-1.0.11.tar.gz

Download URL pyweatherflowrest-1.0.11.tar.gz
Size 15.6 kB
Tags Source
SHA-256 checksum
How to use checksums
766dc11ed8f4176879e149b7a782ef11852200f6f9c59801d2314e7003e6641d
BLAKE2b-256 checksum
How to use checksums
61f3442c08dadf2b7964871aed0b1739542e1d1fa046b557c34a4b333b538f52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / pyweatherflowrest-1.0.11-py3-none-any.whl

Download URL pyweatherflowrest-1.0.11-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5d7fca829dcb97afa32695e1439c30b14a4d61ebca0bb931ab9ef7a3f0d43d1e
BLAKE2b-256 checksum
How to use checksums
ad83f29ee52bffa7d4e5298c922bda2e02f10c13a1265e16efb871979e35e347
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

1.0.11 This release

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.14

1 release file

0.1.13

1 release file

0.1.12

1 release file

0.1.11

1 release file

0.1.10

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page