JTK – Notes and Ramblings Things we have found …

12/26/2025

Weatherflow Tempest MQTT

Filed under: General — taing @ 6:05 am

The Weatherflow Tempest unit has an API based on local broadcast UDP packets. There is also a websocket and a REST API.

This article will focus on using the UDP API with MQTT for use in Openhab. There are a number of resources online. There is a binding that started in 2020 but the discussion stops in 2022. There is a different binding from Bill Welliver that seems more complete.

Additionally there are resources for Home Assistant. https://github.com/briis/hass-weatherflow2mqtt has been depreciated and the git set to read only. It has been replaced with https://github.com/briis/weatherflow_forecast. The newer integration uses a combination the Weaterflow APIs for a more complete setup and also works with Home Assistant discovery. There is also https://github.com/gualandd/WeatherFlow-Tempest-UDP using NodeRed.

All of the options mentioned above seem a bit too heavy for a simple sensor to MQTT path. Here is a bit of python3 code to listen to the UDP port and send to a MQTT broker.

import socket
import paho.mqtt.publish as mqtt
import json

# Define the UDP port to listen on
UDP_IP = "0.0.0.0"  # Listen on all available interfaces
UDP_PORT = 50222
mqtt_host = "your.mqtt.broker"

# Create a UDP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Bind the socket to the specified address and port
sock.bind((UDP_IP, UDP_PORT))

print(f"Listening on {UDP_IP}:{UDP_PORT}...")

# Listen for incoming packets and print them
while True:
    data, addr = sock.recvfrom(1024)  # Buffer size is 1024 bytes
    js = json.loads(data)
#    print(json.dumps(js, indent=4))
    match js['type']:
        case "obs_st":
            mqtt.single('Tempest/obs',json.dumps(js['obs']), hostname=mqtt_host)
            print(f"OBS: {js['obs']}")
        case "rapid_wind":
            mqtt.single('Tempest/wind',json.dumps(js['ob']), hostname=mqtt_host)
            print(f"Wind: {js['ob']}")

This code could easily be expanded to handle more that the obs_st and rapid_wind messages. For now it’s enough. Be sure to update the mqtt_host to point to your broker.

For sending the MQTT messages, the paho-mqtt library is used. The publish.single function can take additional parameters beyond those seen in the script:

  • topic: (Required, string) The topic to publish the message to.
  • payload: (Required, string, bytes, or None) The actual message content.
  • qos: (Optional, int, default 0) The Quality of Service level (0, 1, or 2).
  • retain: (Optional, bool, default False) If set to True, the broker will retain the message as the last known good value for the topic.
  • hostname: (Optional, string, default 'localhost') The IP address or domain name of the MQTT broker.
  • port: (Optional, int, default 1883) The network port of the broker.
  • client_id: (Optional, string) A unique identifier for the client.
  • auth: (Optional, dict) A dictionary containing username and password for authentication (e.g., {'username': "myuser", 'password': "mypass"}).
  • tls: (Optional, dict or None) A dictionary for configuring TLS/SSL secure connections. 

A great intro to using MQTT in python shows installing paho-mqtt using pip3. For a Raspian Buster system apt install python3-paho-mqtt is simpler. Alternatively a virtual environment could be created.

In Openhab, a Generic MQTT thing pointing to your broker is ideal. For most of the sensor data your channels will have the MQTT Topic State set to Tempest/obs. An Incoming Value Transformation using JSONPath will parse the individual readings from the JSON array: JSONPATH:$[0][7], for example, will extract Air Temperature. Refer to the Weatherflow UDP API of the array index of each value. The channels and linked items can be created using the appropriate units for proper conversions.

For Wind Direction a Scale Profile can be created on the Item. This allows for displaying wind direction with compass directions in addition to degrees. For example, E (82 °). The degrees unit is set in the Channel. Create direction.scale in /etc/openhab/transform/ with this content:

[0..11]=N
[12..33]=NNE
[34..56]=NE
[57..79]=ENE
[80..102]=E
[103..125]=ESE
[126..147]=SE
[148..170]=SSE
[171..191]=S
[192..214]=SSW
[215..237]=SW
[238..260]=WSW
[261..283]=W
[284..306]=WNW
[307..329]=NW
[330..352]=NNW
[353..360]=N
NaN=Non-numeric state
format=%label% (%value%)

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress