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

Separate sensors (issue #89) #91

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions custom_components/sems/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,84 @@ def sensor_options_for_data(data) -> List[SensorOptions]:
SensorStateClass.MEASUREMENT,
),
]
battery_count = get_value_from_path(data, path_to_inverter + ["battery_count"])
if battery_count is not None:
for idx in range(0, battery_count):
path_to_battery = path_to_inverter + ["more_batterys", idx]
sensors += [
SensorOptions(
device_info,
f"{serial_number}-{idx}-pbattery",
f"Inverter {inverter['name']} Battery {idx} Power",
path_to_battery + ["pbattery"],
SensorDeviceClass.POWER,
POWER_WATT,
SensorStateClass.MEASUREMENT,
),
SensorOptions(
device_info,
f"{serial_number}-{idx}-vbattery",
f"Inverter {inverter['name']} Battery {idx} Voltage",
path_to_battery + ["vbattery"],
SensorDeviceClass.VOLTAGE,
ELECTRIC_POTENTIAL_VOLT,
SensorStateClass.MEASUREMENT,
),
SensorOptions(
device_info,
f"{serial_number}-{idx}-ibattery",
f"Inverter {inverter['name']} Battery {idx} Current",
path_to_battery + ["ibattery"],
SensorDeviceClass.CURRENT,
ELECTRIC_CURRENT_AMPERE,
SensorStateClass.MEASUREMENT,
),
SensorOptions(
device_info,
f"{serial_number}-{idx}-soc",
f"Inverter {inverter['name']} Battery {idx} State of Charge",
path_to_battery + ["soc"],
SensorDeviceClass.BATTERY,
PERCENTAGE,
SensorStateClass.MEASUREMENT,
),
SensorOptions(
device_info,
f"{serial_number}-{idx}-soh",
f"Inverter {inverter['name']} Battery {idx} State of Health",
path_to_battery + ["soh"],
SensorDeviceClass.BATTERY,
PERCENTAGE,
SensorStateClass.MEASUREMENT,
),
SensorOptions(
device_info,
f"{serial_number}-{idx}-bms_temperature",
f"Inverter {inverter['name']} Battery {idx} BMS Temperature",
path_to_battery + ["bms_temperature"],
SensorDeviceClass.TEMPERATURE,
TEMP_CELSIUS,
SensorStateClass.MEASUREMENT,
),
SensorOptions(
device_info,
f"{serial_number}-{idx}-bms_discharge_i_max",
f"Inverter {inverter['name']} Battery {idx} BMS Discharge Max Current",
path_to_battery + ["bms_discharge_i_max"],
SensorDeviceClass.CURRENT,
ELECTRIC_CURRENT_AMPERE,
SensorStateClass.MEASUREMENT,
),
SensorOptions(
device_info,
f"{serial_number}-{idx}-bms_charge_i_max",
f"Inverter {inverter['name']} Battery {idx} BMS Charge Max Current",
path_to_battery + ["bms_charge_i_max"],
SensorDeviceClass.CURRENT,
ELECTRIC_CURRENT_AMPERE,
SensorStateClass.MEASUREMENT,
),
]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the values from more_batterys that I think I know what they are.

If you know what the other values are I can try and add them

     #{
        "pbattery": 0.0,
        "vbattery": 205.1,
        "ibattery": 0.0,
        "battary_work_mode": 1,
        "battstrings": 4.0,
        "bms_status": 1,
        "bms_temperature": 23.0,
        "bms_discharge_i_max": 40.0,
        "bms_charge_i_max": 40.0,
        "bms_alarm_l": 0,
        "bms_warning_l": 0,
        "soc": 5.0,
        "soh": 100.0,
        "bmsbattstr": 4,
        "batteryprotocol": 1234,
        "bms_alarm_h": 0,
        "bms_warning_h": 0,
        "bmssoftwareversion": 0.0,
        "batteryhardwareversion": 0.0,
        "batttotalcharge": 0.0,
        "batttotaldisCharge": 0.0,
        "batterysnmain": "",
        "bms_alarm": 0,
        "bms_warning": 0
    }

Copy link

@f00f f00f Nov 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! 👏

soc is State of Charge
soh is State of Health
vbattery is probably the voltage, bms_temperature the reported temperature.
I'd assume that one value may indicate the flow direction, i.e. charging, nothing, or discharging. Maybe that's battery_work_mode.
All the other values don't look very interesting, or look like they would not be supported by my battery.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realized that you already had all the ones I mentioned...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@f00f did you censor "batterysnmain" i think it might stand for Battery Serial Number Main


if "hasPowerflow" in data and data["hasPowerflow"] and "powerflow" in data:
serial_number = "powerflow"
Expand Down