# UDP Rain Event only from Sky (?)

**URL:** <https://community.tempest.earth/t/udp-rain-event-only-from-sky/12635>\
**Category:** Developers\
**Created:** [March 11, 2021, 1:55pm UTC](https://community.tempest.earth/t/udp-rain-event-only-from-sky/12635 "2021-03-11T13:55:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![andyhudsonsmith](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@andyhudsonsmith](https://community.tempest.earth/u/andyhudsonsmith)\
**Post date:** [March 11, 2021, 1:55pm UTC](https://community.tempest.earth/t/udp-rain-event-only-from-sky/12635/1 "2021-03-11T13:55:34Z")

</div>

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 🙂

```
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")
```

---

<div class="post-metadata">

**Author:** ![btst.online](https://sea2.discourse-cdn.com/flex020/user_avatar/community.tempest.earth/btst.online/32/16538_2.png) [@btst.online](https://community.tempest.earth/u/btst.online)\
**Post date:** [March 11, 2021, 1:57pm UTC](https://community.tempest.earth/t/udp-rain-event-only-from-sky/12635/2 "2021-03-11T13:57:47Z")

</div>

Yes, you can.  
When you check the ‘parsed\_data’ for ‘evt\_precip’, also check the ‘serial\_number’ to be that of your SKY.  
–Sam

---

<div class="post-metadata">

**Author:** ![andyhudsonsmith](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@andyhudsonsmith](https://community.tempest.earth/u/andyhudsonsmith)\
**Post date:** [March 11, 2021, 2:11pm UTC](https://community.tempest.earth/t/udp-rain-event-only-from-sky/12635/3 "2021-03-11T14:11:59Z")

</div>

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

---

<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:** [March 11, 2021, 2:45pm UTC](https://community.tempest.earth/t/udp-rain-event-only-from-sky/12635/4 "2021-03-11T14:45:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![andyhudsonsmith](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@andyhudsonsmith](https://community.tempest.earth/u/andyhudsonsmith)\
**Post date:** [March 11, 2021, 2:47pm UTC](https://community.tempest.earth/t/udp-rain-event-only-from-sky/12635/5 "2021-03-11T14:47:57Z")

</div>

> [@peter](#):
>
> and

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

Andy
