UDP Rain Event only from Sky (?)


Probably a simple question - but - i have a UDP listener, listening for evt_precip. It picks up my tempest device and my sky. The Tempest gives a lot of false rain readings (I’m working on it) - so the question is, can i filter the UDP to only look for evt_precip from my Sky unit?

The scripts rings a physical bell twice when it rains :slight_smile:

import socket

import json
import time
import paho.mqtt.publish as publish

#Set Output Message - Number relates to the angle to move the servo to hit the bell

#Set up and listen to UDP Broadcasts

while True:
UDP_IP = “”
UDP_PORT = 50222

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(('', UDP_PORT))
data, addr = s.recvfrom(1024)
parsed_data = json.loads(data.decode("utf-8"))
if parsed_data["type"] == "evt_precip": 
    rainevent = (parsed_data)
    output = int(47)
    print("Publishing message to topic")
    publish.single("ringbell/ring", output, hostname="")
    print (output)
    publish.single("ringbell/ring", output, hostname="mymqtt")
    print (output)
    publish.single("led/home", "It has started to Rain", hostname="mymqtt")  
    print ("It has started to Rain")

Yes, you can.
When you check the ‘parsed_data’ for ‘evt_precip’, also check the ‘serial_number’ to be that of your SKY.

1 Like

Brilliant - that was my hunch - so I put in my serial of the sky - ie

if (parsed_data[“type”] == “evt_precip”) & (parsed_data [“serial_number”] == (“SK-00009880”))

but it failed to fire on a rain event, so i was wondering if the rain event was seperate… (?)


On a very quick glance, you might just need to change the


in your logical expression to


The ampersand tells Python to do a bitwise comparison which is not what you want.


Yep - just tried it and it works :slight_smile: great, thanks a lot…