StephanJoubert / home_assistant_solarman

Home Assistant component for Solarman collectors used with a variety of inverters.
Apache License 2.0
508 stars 191 forks source link

New Rule Option #449

Open cyberrep opened 7 months ago

cyberrep commented 7 months ago

Hey buddy how you doing? Im trying to get all values from the inversor and one of them came in HEX ['0x5148']
DC MASTER FW VERSION I use rule 6 to find image

SOLARMAN DETAILS image

I dont know if its QH the version or the 5.1.4.8 its the correct one If 5.1.4.8, can you add a new rule to get just the 5148 and we can use the mask option

cyberrep commented 7 months ago

I'm doing a better way, I'll add my code, my modebus (yellow items its all items I put in the config) and some print, if you wanna help to fix these values: HOMEASSISTANT

image

SOLARMAN BASIC DETAILS SHOW image

MY CODE

deye_2mppt.zip

modbus Modbus-组串-微逆宁波德业V117(3).zip

cyberrep commented 7 months ago

I did some tests and create the rule: 9, if is possible, add this to the next release ;-) its read the value , if is hex, leave just the number after the "x"

def try_parse_hex(self, rawData, definition, start, length):
    title = definition['name']
    found = True
    value = ''

    for r in definition['registers']:
        index = r - start  # get the decimal value of the register
        if 0 <= index < length:
            offset = OFFSET_PARAMS + (index * 2)
            temp = struct.unpack('>H', rawData[offset:offset + 2])[0]
            hex_value = hex(temp)

            # Extract values after 'x'
            value += hex_value.split('x')[1]
        else:
            found = False

    if found:
        self.result[title] = value
    return
cyberrep commented 7 months ago

its better now. Just figure out how to show the system time

- name: "System Time" #System time   -----------------------------------------NEED TO FIX
  class: ""
  state_class: ""
  uom: ""
  scale: 1
  rule: 6 # RESULT OF 0x0016 = FIRST 2 = YEAR, MONTH / 0x0017 = FIRST 2 = DAY, HOUR / 0x0018 = FIRST 2 = MIN, SEC
  registers: [0x0016,0x0017,0x0018] #22,23,24 

image

image

cyberrep commented 7 months ago

done for rule 10 ;-) "try_parse_datetime_hex" from this [0x170b, 0x100d, 0x392a]

image

def try_parse_datetime_hex(self, rawData, definition, start, length):
    title = definition['name']
    found = True
    value = ''

    for r in definition['registers']:
        index = r - start  # get the decimal value of the register
        if 0 <= index < length:
            offset = OFFSET_PARAMS + (index * 2)
            temp = struct.unpack('>H', rawData[offset:offset + 2])[0]
            hex_value = hex(temp)

            # Extract values after 'x'
            hex_part = hex_value.split('x')[1]

            # Check if hex_part has 3 characters, add '0' at the beginning
            if len(hex_part) == 3:
                hex_part = '0' + hex_part

            value += hex_part

    if found:
        # Convert hex values to decimal
        year = 2000 + int(value[0:2], 16)
        month = int(value[2:4], 16)
        day = int(value[4:6], 16)
        hour = int(value[6:8], 16)
        minute = int(value[8:10], 16)
        second = int(value[10:12], 16)

        # Format the result
        formatted_result = f"{month:02d}/{day:02d}/{year:04d}, {hour:02d}:{minute:02d}:{second:02d}"

        self.result[title] = formatted_result
    return

image