UDP Rain Event only from Sky (?)

Afternoon,

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(('0.0.0.0', 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)
    time.sleep(1)
    print("Publishing message to topic")
    publish.single("ringbell/ring", output, hostname="192.168.1.76")
    time.sleep(2)
    print (output)
    publish.single("ringbell/ring", output, hostname="mymqtt")
    time.sleep(1)
    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.
–Sam

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… (?)

Andy

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

&

in your logical expression to

and

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

2 Likes

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

Andy

2 Likes