Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrections #25

Open
s118 opened this issue Feb 18, 2024 · 5 comments
Open

Corrections #25

s118 opened this issue Feb 18, 2024 · 5 comments

Comments

@s118
Copy link

s118 commented Feb 18, 2024

The code doesn't work. I pass the code with corrections, although the comments are in Spanish. I have added the "exportar" variable, in case you want to export some energy to the grid. If you do not want to export anything, exportar=0

#!/usr/bin/env python3
import requests, time, sys
from requests.auth import HTTPBasicAuth

Ajustar estos datos

serial = "xxxxxxxxxxxxxxx" # numero serie microinversor
maximum_wr = 2000 # Máxima salida del microinversor
minimum_wr = 100 # Minima salida del microinversor
dtu_ip = 'xxxxxxxxxxxx' # IP Adresse OpenDTU
basicdtu = HTTPBasicAuth('admin', 'xxxxxxxx')
dtu_user = 'admin' # usuario openDTU
dtu_pass = 'xxxxxxxxxxx' # OpenDTU Password
basicShelly = HTTPBasicAuth('admin', 'xxxxxxx')
shelly_ip = 'xxxxxxxxxx' # IP Adresse Shelly 3EM
grid= 0
power = 0
reachable = 0
exportar = 1500
valor_seguridad = 0
while True:
try:
# Toma de datos de la API REST de openDTU y los convierte en json-Format
r = requests.get(url = f'http://{dtu_ip}/api/livedata/status/inverters', headers={'Content-Type': 'application/json'},auth=basicdtu).json()
# Selecciona los datos especificos de la respuesta json
reachable = r['inverters'][0]['reachable'] # es accesible la DTU?
producing = int(r['inverters'][0]['producing']) # El microinversor está produciendo?
viejo_limite = int(r['inverters'][0]['limit_absolute']) # Viejo límite
power = r['total']['Power']['v'] # Entrega de corriente alterna en W
except:
print('Error al recuperar datos de openDTU')
try:
# Toma datos de Shelly 3EM Rest API y los traduce a formato json
grid = requests.get(f'http://{shelly_ip}/emeter/2', headers={'Content-Type': 'application/json'},auth=basicShelly).json()['power']
except:
print('Error al recuperar datos de Shelly 3EM')
# Establecer valores
print(f'\nRed: {round(grid, 1)} W, Produccion: {round(power, 1)} W, Casa: {round(grid + power, 1)} W')
if reachable:
setpoint = grid + viejo_limite - valor_seguridad + exportar # Nuevos límites en W
# Límite superior de captura
if setpoint > maximum_wr:
setpoint = maximum_wr
print(f'Estableciendo Maximo: {maximum_wr} W')
# Límite inferior de captura
elif setpoint < minimum_wr:
setpoint = minimum_wr
print(f'Estableciendo Minimo: {minimum_wr} W')
else:
print(f'Ajuste Calculado: {round(grid, 1)} W + {round(viejo_limite, 1)} W - valor_seguridad W = {round(setpoint, 1)} W')
if setpoint != viejo_limite:
print(f'Establecer el límite del inversor de {round(viejo_limite, 1)} W a {round(setpoint, 1)} W... ', end='')
# Establecer un nuevo límite
try:
r = requests.post(
url = f'http://{dtu_ip}/api/limit/config',
data = f'data={{"serial":"{serial}", "limit_type":0, "limit_value":{setpoint}}}',
auth = HTTPBasicAuth(dtu_user, dtu_pass),
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
)
print(f'Configuracion enviada ({r.json()["type"]})')
except:
print('Error al enviar la configuracion')
sys.stdout.flush() # escribir mensajes almacenados en caché en stdout
time.sleep(5) # esperar

@Selbstbau-PV
Copy link
Owner

The script works only with opnedtu lower than V24.1.26

@greymda
Copy link

greymda commented Mar 22, 2024

@s118 what opendtu version are you on? thanks for the updated script.

@s118
Copy link
Author

s118 commented Mar 22, 2024

Hy. When I modified the original code, it was on version v24.2.12. I am currently on version v24.2.16 and everything is working without problems. Tomorrow I will test new versions, and in case of news, I will communicate them.

@greymda
Copy link

greymda commented Mar 25, 2024

Hy. When I modified the original code, it was on version v24.2.12. I am currently on version v24.2.16 and everything is working without problems. Tomorrow I will test new versions, and in case of news, I will communicate them.

@s118 have you had a chance to test it? cheers

@s118
Copy link
Author

s118 commented Mar 28, 2024

Hello. Today I tested it, and although it was a rainy day, the code worked perfectly. Attached graph that represents the percentage of the microinverter's work limit throughout the day. The production of the microinverter (HOYMILES HMS-2000) is also represented.
Captura

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants