Frankkkkk / python-pylontech

Python lib to talk to pylontech lithium batteries 🔋 (US2000, US3000, ...) using RS485
MIT License
67 stars 32 forks source link

Help with coding #39

Open Minoslo opened 9 months ago

Minoslo commented 9 months ago

Is there any chance to help me to implement this code for a GUI? What I exactly need is to run few commands to get SoC and temperature values. I'm new on this topic and any help would be appreciated. I have been reading the protocol and I think I understand how it works but I don't know how to send a command using a python script.

Frankkkkk commented 9 months ago

Hi, A simple "hello" is always welcome :-) Basically, the library implements most of the commands. There are some examples here.

Once you choose a GUI lib (tkinter for example), you just have to interface with this library and it should work :-)

Maybe I'll write an example if I have the time, but I don't guarantee it. Cheers

Minoslo commented 9 months ago

Oh man...I'm so sorry, for real. My comment was rude (english is not my native language so I was stupdly focus trying to explain myself), I apologize. Let me start over. Hello mate , Your lib is really awesome and it had helped me so much on my project. I was able to use most of the commands except "p.get.values()". I found your project meanwhile I was trying to use the pylon protocol myself but I don't have enough knowledge to do it. I will try to do what you told me. I'm currently using "pysimplegui" to make my GUI. Any example would be appreciated if you have time. Thank you very much for the fast answer tho. Cheers.

Frankkkkk commented 9 months ago

No problem ;-) Something like that should do the job: image

import tkinter as tk
from time import time
from pylontech import Pylontech

p = Pylontech()

def update():
    vals = p.get_values()
    bv = vals.Module[0].Voltage
    bi = vals.Module[0].Current
    tot_power = vals.TotalPower
    batv_v.config(text=f"{bv} V")
    bati_v.config(text=f"{bi} A")
    batp_v.config(text=f"{tot_power} W")
    root.after(5000, update)

# Create the main window
root = tk.Tk()
root.title("Pylontech Display")

# Create a label widget for displaying the time
batv_l = tk.Label(root, text="Battery Voltage")
batv_l.grid(column=0, row=0)
batv_v = tk.Label(root, text="xx V")
batv_v.grid(column=1, row=0)

bati_l = tk.Label(root, text="Battery Current")
bati_l.grid(column=0, row=1)
bati_v = tk.Label(root, text="xx A")
bati_v.grid(column=1, row=1)

batp_l = tk.Label(root, text="Battery Power")
batp_l.grid(column=0, row=2)
batp_v = tk.Label(root, text="xx W")
batp_v.grid(column=1, row=2)

time_label2 = tk.Label(root, font=('Helvetica', 48), pady=20)
#time_label2.pack()

# Initialize the time display
update()

# Start the Tkinter event loop
root.mainloop()

Warning: it's horrible code straight out of gpt, but it kinda works

Cheers

Frankkkkk commented 9 months ago

PS: If you create a nice UI, it'd be great if you could do an MR someday so we can add it to the repo !

Minoslo commented 9 months ago

Hello mate 😊, Thank you a lot! That's the example that I need it to know how the info was grouped within the response. When I finish the GUI, you can be sure I will do an MR and if you like the GUI enough, it would be awesome to add it here and help another people. Thank you one more time for being so quick to answer.

Cheers