# Basic Python websockets example to retrieve current Tempest data

**URL:** https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310
**Category:** Developers
**Tags:** code-sample
**Created:** [September 14, 2020, 11:33pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310 "2020-09-14T23:33:59Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![dwburger](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dwburger](https://community.tempest.earth/u/dwburger)
#### Post date: [September 14, 2020, 11:33pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/1 "2020-09-14T23:33:59Z")

</div>

I’m relatively new to Python and wondered whether anyone could point me to a very basic example of retrieving current data from my Tempest using Python websockets. To get started, all I want to do is open a socket, get the current data from my Tempest in the console and close the socket. I’ve been trying to use the online documentation, but I haven’t been successful. There’s something missing in my understanding of the process and I’m hoping a simple example will get me over the the hump. Thanks for any help provided!

---

<div class="post-metadata">

### Author: ![peter](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/peter/32/1365_2.png) [@peter](https://community.tempest.earth/u/peter)
#### Post date: [September 15, 2020, 8:13am UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/2 "2020-09-15T08:13:29Z")

</div>

This is the simplest example I could come up with. It will connect to the Websocket, start listening for Tempest messages, and then disconnect once it has received a single data message:

```auto
from websocket import create_connection

personal_token = ' '
tempest_ID = ' '

print('Opening Websocket connection...')
ws = create_connection('wss://ws.weatherflow.com/swd/data?api_key=' + personal_token)
result = ws.recv()
print("Received '%s'" % result)
print('')

print('Listening to Tempest endpoint...')
ws.send('{"type":"listen_start",' + ' "device_id":' + tempest_ID + ',' + ' "id":"Tempest"}')
result = ws.recv()
print("Received '%s'" % result)
print('')

print('Receiving Tempest data...')
result = ws.recv()
print("Received '%s'" % result)
print('')

ws.close()

```

You need to install the Python websockets module with `python3 -m pip install websocket-client` ([https://pypi.org/project/websocket\_client/](https://pypi.org/project/websocket_client/)) and in the code above you need to enter a [personal access token](https://tempestwx.com/settings/tokens) and device ID of your Tempest as strings. Hope this help

---

<div class="post-metadata">

### Author: ![dwburger](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dwburger](https://community.tempest.earth/u/dwburger)
#### Post date: [September 15, 2020, 2:51pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/3 "2020-09-15T14:51:25Z")

</div>

That’s a BIG help…thanks! I got it working just fine. Now that I see how it works, I think the online documentation will make more sense to me. I really appreciate the help!

---

<div class="post-metadata">

### Author: ![wrybread](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@wrybread](https://community.tempest.earth/u/wrybread)
#### Post date: [December 21, 2025, 9:24pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/4 "2025-12-21T21:24:27Z")

</div>

Did you ever get this working? Not working for me. I’m trying to get the data from my station, which I can see is uploading wind data every few seconds:

> **[Tempest](https://tempestwx.com/station/54330/grid)**
>
> Tempest Weather System

But this slightly modified version of the above Python script never gets any data, it just sits on “Listening to Tempest endpoint…”

```auto
#!/usr/bin/python

# pip install websocket-client
import websocket

personal_token = '[REMOVED]'

tempest_ID = '54330'

print('Opening Websocket connection...')

# I added this line, turns on extra logging -wb
websocket.enableTrace(True)

ws = websocket.create_connection('wss://ws.weatherflow.com/swd/data?api_key=' + personal_token)
result = ws.recv()
print("Received '%s'" % result)
print('')

print('Listening to Tempest endpoint...')
ws.send('{"type":"listen_start",' + ' "device_id":' + tempest_ID + ',' + ' "id":"2098388936"}') # changed id from "Tempest" -wb
result = ws.recv()
print("Received '%s'" % result)
print('')

print('Receiving Tempest data...')
result = ws.recv()
print("Received '%s'" % result)
print('')

ws.close()

```

I tried changing the “tempest\_ID” from “Tempest” to “2098388936”, which the docs say will return all data:

> **[Reference](https://apidocs.tempestwx.com/reference/websocket-reference)**
>
> A quick start guide to using the Tempest WebSocket API.

But no luck. Here’s the output. Note that I turned on “enableTrace” so this has more output than the original example:

```auto
[iad1-shared-b7-30]$ ./tempestReader.py
Opening Websocket connection...
--- request header ---
GET /swd/data?api_key=[REMOVED] HTTP/1.1
Upgrade: websocket
Host: ws.weatherflow.com
Origin: https://ws.weatherflow.com
Sec-WebSocket-Key: [REMOVED]
Sec-WebSocket-Version: 13
Connection: Upgrade

-----------------------
--- response header ---
HTTP/1.1 101 Web Socket Protocol Handshake
Date: Sun, 21 Dec 2025 21:21:17 GMT
Connection: upgrade
Server: Payara Server 6.2023.2 #badassfish
X-Powered-By: Servlet/6.0 JSP/3.1 (Payara Server 6.2023.2 #badassfish Java/Amazon.com Inc./11)
Sec-WebSocket-Accept: IOid/LUoqdN/3cIowhCccH/PlUM=
Upgrade: websocket
-----------------------
++Rcv raw: b'\x81\x1c{"type":"connection_opened"}'
++Rcv decoded: fin=1 opcode=1 data=b'{"type":"connection_opened"}'
Received '{"type":"connection_opened"}'

Listening to Tempest endpoint...
++Sent raw: b'\x81\xbd\xc7\xbd\x18e\xbc\x9fl\x1c\xb7\xd8:_\xe5\xd1q\x16\xb3\xd8v:\xb4\xc9y\x17\xb3\x9f4E\xe5\xd9}\x13\xae\xde}:\xae\xd9:_\xf2\x89+V\xf7\x918G\xae\xd9:_\xe5\x8f(\\\xff\x8e ]\xfe\x8e.G\xba'
++Sent decoded: fin=1 opcode=1 data=b'{"type":"listen_start", "device_id":54330, "id":"2098388936"}'

```

Or maybe I’m misunderstanding what the websocket method is supposed to do? Ultimately I’m trying to build a small display that shows the wind data every few seconds, like a standard weather station physical display.

---

<div class="post-metadata">

### Author: ![dwburger](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dwburger](https://community.tempest.earth/u/dwburger)
#### Post date: [December 21, 2025, 9:53pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/5 "2025-12-21T21:53:58Z")

</div>

Yes, I was able to get my Python script to work. It gets Tempest data and then uses that data to calculate ET0. You can see my Python script here:

[https://github.com/dwburger/Tempest-ET0](https://github.com/dwburger/Tempest-ET0)

---

<div class="post-metadata">

### Author: ![wrybread](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@wrybread](https://community.tempest.earth/u/wrybread)
#### Post date: [December 21, 2025, 10:23pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/6 "2025-12-21T22:23:36Z")

</div>

Thanks for that. Looks like you abandoned the websockets method. I was just doing the same when you responded. Oh well, back to good ol polling. And thanks for your script.

---

<div class="post-metadata">

### Author: ![wrybread](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@wrybread](https://community.tempest.earth/u/wrybread)
#### Post date: [December 21, 2025, 10:30pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/7 "2025-12-21T22:30:03Z")

</div>

And are you able to get frequent updates? Looking at my public dashboard I can see the wind speed changing every 3 or so seconds. But when polling the API I only get an update about once a minute.

I’m using obs[0][“wind\_avg”] for the wind speed.

Here’s a sample reply from my weather station:

> <https://pastebin.com/raw/CSShYpmf>

---

<div class="post-metadata">

### Author: ![dwburger](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dwburger](https://community.tempest.earth/u/dwburger)
#### Post date: [December 21, 2025, 11:38pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/8 "2025-12-21T23:38:14Z")

</div>

My Python script runs only once per hour. Since you’re using wind\_avg data from the Tempest, I wonder how often it’s actually polling the wind speed sensor.

---

<div class="post-metadata">

### Author: ![wrybread](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@wrybread](https://community.tempest.earth/u/wrybread)
#### Post date: [December 21, 2025, 11:49pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/9 "2025-12-21T23:49:20Z")

</div>

Tried using wind\_gust too, which shouldn’t be averages, but it’s only updating once per minute as well.

---

<div class="post-metadata">

### Author: ![dwburger](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dwburger](https://community.tempest.earth/u/dwburger)
#### Post date: [December 22, 2025, 12:07am UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/10 "2025-12-22T00:07:08Z")

</div>

Have you tried folks at Tempest to see if they can tell you how often data is updated?

---

<div class="post-metadata">

### Author: ![wrybread](https://avatars.discourse-cdn.com/v4/letter/w/c89c15/32.png) [@wrybread](https://community.tempest.earth/u/wrybread)
#### Post date: [December 22, 2025, 5:35am UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/11 "2025-12-22T05:35:01Z")

</div>

Looks like the API is limited to 1 minute updates. Oh well, I guess they’re worried about server load. Can get more frequent updates if you’re on the same LAN as the weather station using other methods though.

---

<div class="post-metadata">

### Author: ![dwburger](https://avatars.discourse-cdn.com/v4/letter/d/8dc957/32.png) [@dwburger](https://community.tempest.earth/u/dwburger)
#### Post date: [December 22, 2025, 5:50am UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/12 "2025-12-22T05:50:04Z")

</div>

Good to know…thanks!

---

<div class="post-metadata">

### Author: ![mabeatty1978](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/mabeatty1978/32/15139_2.png) [@mabeatty1978](https://community.tempest.earth/u/mabeatty1978)
#### Post date: [March 6, 2026, 8:24pm UTC](https://community.tempest.earth/t/basic-python-websockets-example-to-retrieve-current-tempest-data/9310/13 "2026-03-06T20:24:53Z")

</div>

The websocket integration only sends observation data back once per minute. Rain and lightning events are triggered whenever they happen.

To get wind readings in real time, you need to sniff the UDP messages from your hub which are broadcast over your local network. Here is a sample Python program [Simple-WeatherFlow-Python-Listener/weatherflow\_listener.py at master · MABeatty1978/Simple-WeatherFlow-Python-Listener · GitHub](https://github.com/MABeatty1978/Simple-WeatherFlow-Python-Listener/blob/master/weatherflow_listener.py)
