I am using a Lillygo with BYD-Battery-Emulator-For-Gen24. I would like to use the USB port with debugging information to show status and data of the battery in Homeassistant.
Somehow I can not get the individual items filtered out of the input data of the serial data. What is going wrong here?
(I am not a great coder as you can see, thank you for your help)
Serial data what I receive:
Please wait for Pyro Connection check to finish, HV cables successfully seated!
Contactor: OPEN , HVIL: STATUS_OK , NegativeState: OPEN , PositiveState: OPEN, setState: OPEN, close allowed: 1, Pyrotest: 1
Battery values:
Vi SOC: 591 SOC max: 604 SOC min: 595 SOC avg: 600, Battery voltage: 369, Battery amps: 0, Discharge limit battery (kW): 0, Charge limit battery (kW): 0, Fully charged?: 0, Min discharge voltage allowed: 240, Max charge voltage allowed: 403, Max charge current (A): 0, Max discharge current (A): 0
Cellstats, Max mV: 3858, on cell no#: 8, Min mV: 3848, on cell no#: 88
HighVoltage Output Pins: 9, V, Low Voltage:12, V, Current Output:0
Values heading towards inverter:
SOC% (XX.XX%): 5910 Max discharge power (W): 0 Max charge power (W): 0 Max temperature (C): 160 Min temperature (C): 150
Code made for my sensors.yaml:
# Battery via Lillygo
- platform: serial
name: home_battery
serial_port: /dev/ttyACM1
baudrate: 9600
- platform: template
sensors:
contactor_state:
friendly_name: Contactor State
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("Contactor: (\w+)", 0) }}
hvil:
friendly_name: HVIL
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("HVIL: (\w+)", 0) }}
negative_state:
friendly_name: Negative State
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("NegativeState: (\w+)", 0) }}
positive_state:
friendly_name: Positive State
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("PositiveState: (\w+)", 0) }}
set_state:
friendly_name: Set State
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("setState: (\w+)", 0) }}
close_allowed:
friendly_name: Close Allowed
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("close allowed: (\d)", 0) | int }}
pyrotest:
friendly_name: Pyrotest
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("Pyrotest: (\d)", 0) | int }}
vi_soc:
friendly_name: Vi SOC
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("Vi SOC: (\d+)", 0) | int }}
soc_max:
friendly_name: SOC Max
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("SOC max: (\d+)", 0) | int }}
soc_min:
friendly_name: SOC Min
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("SOC min: (\d+)", 0) | int }}
soc_avg:
friendly_name: SOC Average
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("SOC avg: (\d+)", 0) | int }}
battery_voltage:
friendly_name: Battery Voltage
value_template: >-
{{ states('sensor.home_battery') | regex_findall_index("Battery voltage: (\d+)", 0) | int }}