-
Notifications
You must be signed in to change notification settings - Fork 28
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
Comments
The script works only with opnedtu lower than V24.1.26 |
@s118 what opendtu version are you on? thanks for the updated script. |
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 |
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
The text was updated successfully, but these errors were encountered: