Jump to content
Fixed! Bug in Scenes Feature ×

Close box awnings (sunshade) when rain is expected


Recommended Posts

Posted (edited)

I made a script that checks if it is raining or will rain in the coming 20 minutes. If so, it should close my sunshade using a Shelly Plus 2PM. However, I can't seem to find how to fix this and can't find any examples of how its done. I want to run my script in some cloud service provider like Google Cloud and let it check every 5 minutes. It should send a call to my Shelly device to close when rain returns True.

Can someone explain me what I'm doing wrong here? And point in me in the right direction?


import requests
import statistics
lat = 50.0
lon = 5.0
url = f"https://gadgets.buienradar.nl/data/raintext/?lat={lat}&lon={lon}"
response = requests.get(url)
raindata = response.text
rain_dict = {}
for line in raindata.splitlines()[:5]:
value, time = line.split("|")
rain_dict[str(time.strip())] = int(value.strip())
rain_values = list(rain_dict.values())
median_value = statistics.median(rain_values[1:5])
if rain_values[0] > 5:
rain = True
elif median_value > 15:
rain = True
rain = False
# Shelly Cloud API-gegevens
shelly_cloud_url = < my url >
shelly_device_id = < my id >
shelly_username = < my username >
shelly_password = < my password >
def close_sunshade():
headers = {
"Content-Type": "application/json"
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "Switch.Set",
"params": {
"id": shelly_device_id,
# "auth_key": f"{shelly_username}:{shelly_password}", # Greyed out because auth is turned off
"on": True
response = requests.post(shelly_cloud_url, json=payload, headers=headers, verify=False)
if response.status_code == 200:
print("Sunshade closed successfully via Shelly Cloud")
print("Failed to close sunshade via Shelly Cloud")
rain=True # Overwrite rain to True, for testing purposes
if rain:
Edited by Brnfnk
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...