Jump to content
⚠️ Deprecation Notice: Cloud Control API V1 – Switch to V2 ×

Py script to download current day production and consumption data


Recommended Posts

Posted

Hello,

I trying to run a py script from a server (192.168.0.10) to export current day production and consumption data from Shelly Pro 3EM (192.168.0.73)

The script is hosted by local Raspberry server, hower when trying to run the script a syntaxe error is reported on that line :

Quote

root@RASPBX:/home/shelly# python3 /home/shelly/export_shelly_data.py
  File "/home/shelly/export_shelly_data.py", line 19
    response = requests.get(f'http://{shelly_ip}/status')
                                                                                        ^
SyntaxError: invalid syntax

import requests
import csv
from datetime import datetime
from ftplib import FTP

# Configuration
shelly_ip = "192.168.0.73"  # Shelly Pro 3EM IP
ftp_server = "192.168.0.10"
ftp_user = "user"
ftp_password = "password"
ftp_directory = "/1Tb/Shelly_data_export"

# Retrieve data from Shelly Pro 3EM
response = requests.get(f'http://{shelly_ip}/status')
response = requests.get(f'http://{shelly_ip}/rpc/Shelly.GetComponents'); components = response.json()
data = response.json()

# Data Extraction
production = data['emeters'][0]['total']
consumption = data['emeters'][1]['total']

# CSV file generation
filename = f'data_{datetime.now().strftime("%Y-%m-%d")}.csv'
with open(filename, mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['Date', 'Production', 'Consommation'])
writer.writerow([datetime.now().strftime("%Y-%m-%d"), production, consumption])

# Send CSV to FTP server
ftp = FTP(ftp_server)
ftp.login(ftp_user, ftp_password)
ftp.cwd(ftp_directory)
with open(filename, 'rb') as file:
ftp.storbinary(f'STOR {filename}', file)
ftp.quit()

print(f'Fichier {filename} successfully sent over FTP.')

Can someone tell what is wrong with that script ?

Regards,

Join the conversation

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

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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...