-
Notifications
You must be signed in to change notification settings - Fork 38
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
base: master
Are you sure you want to change the base?
Conversation
I don't have too much time to look at it yet, but at first glance it seems we can do some code deduplication. :) |
…oints. Update manifest.json with iot_class and integration_type. Change version to 4.0.0
I bumped the version to 4.0.0 to reflect the fact we are removing the attributes and as such will break any templates, etc using the attributes. |
if self._empty_value is not None and self._empty_value == value: | ||
value = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I receive None
values for some attributes, e.g. ['inverter', 0, 'invert_full', 'vpv3']
. They cause an unhandled exception, so all updates of values failed. My quick fix is to detect None
and treat it as 0
. You may instead consider a try-catch around the conversion.
if self._empty_value is not None and self._empty_value == value: | |
value = 0 | |
if self._empty_value is not None and self._empty_value == value: | |
value = 0 | |
if None == value: | |
_LOGGER.debug(f"Value was 'None': {self._value_path}") | |
value = 0 |
When configuring the Energy dashboard, I don't see sensors for battery in the dropdown list. |
custom_components/sems/sensor.py
Outdated
batteries = [ | ||
Sensor( | ||
coordinator, | ||
device_info, | ||
f"{serial_number}-vbattery1", | ||
f"Inverter {inverter['name']} Battery Voltage", | ||
path_to_inverter + ["vbattery1"], | ||
Decimal, | ||
SensorDeviceClass.VOLTAGE, | ||
ELECTRIC_POTENTIAL_VOLT, | ||
SensorStateClass.MEASUREMENT, | ||
), | ||
Sensor( | ||
coordinator, | ||
device_info, | ||
f"{serial_number}-ibattery1", | ||
f"Inverter {inverter['name']} Battery Current", | ||
path_to_inverter + ["ibattery1"], | ||
Decimal, | ||
SensorDeviceClass.CURRENT, | ||
ELECTRIC_CURRENT_AMPERE, | ||
SensorStateClass.MEASUREMENT, | ||
), | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When configuring the Energy dashboard, I don't see sensors for battery in the dropdown list. Is the sensor simply missing from this PR? Does the api not provide the data? Can I build a custom sensor from available data?
I don't have a battery so I am making some assumptions about what these values will look like, if you could provide the API response JSON you are getting from the SEMS portal we can improve this. Make sure you don't include any personal info the start of the JSON normally contains your name ect.
This looks great to me (as somebody who just started using this integration yesterday). |
Do you have a homekit installed? |
Battery: here's the response I get from SEMS: https://gist.github.com/f00f/6eb432ca01b66827aa24a59c570e0d84 Homekit=None: I have no Homekit installed and also the sn=None issue. To me it's just cosmetic, but I haven't read #92, yet. |
Account for None path values or missing paths. Add some tests.
custom_components/sems/sensor.py
Outdated
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, | ||
), | ||
] |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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
I haven't really tested the latest changes, might get a chance on the weekend. |
I have installed the latest version. Now all entities that I had are unavailable and I have a copy of them with suffix "_2", e.g. This breaks all dashboards etc. If you could make your last changes in a way that I get my old sensors back, that would be much appreciated. Otherwise, I definitely can scratch everything and start over. |
I made it so the powerflow sensors are not related to the homekit sn. Some people don't have a home kit but still had powerflow stats. So I have made a change to check if you already have a homekit sensor and keep the old naming method if so. This should prevent the _2 named sensors being created. |
Thank you, I really appreciate that! |
Try and handle bug in the goodwe api where it returns zero when close to midnight. @see TimSoethout#94
I haven't contributed any code for this release but I have the "no serial number homekit" that I hacked in #92 ... |
I use the "Studio Code Server" addon and paste my code from Pycharm then restart home assistant. |
Sorry I meant the best process to this this branch/build before you guys release it, not how to develop my own modifications to it 😀 is that a rough ETA for this release? |
I don't know how HACS works so am not sure whats required on that side of things. The code in this pull request is working for me. The main issue I am having is #94 which is ruining my energy dashboard. @TimSoethout whats required to release to HACS? |
I think git tagging a commit with a version, updating the version in the manifest json and creating a GitHub release. Is is also possible to create a beta release of a branch.
Both of which require some input from me.
Local testing can be done without HACS by creating a development environment using HA's instructions. Or just dropping the files in your `custom_components` directory.
28 Jan 2024 00:47:32 Kyah Rindlisbacher ***@***.***>:
…
I don't know how HACS works so am not sure whats required on that side of things. The code in this pull request is working for me. The main issue I am having is #94[#94] which is ruining my energy dashboard.
@TimSoethout[https://github.com/TimSoethout] whats required to release to HACS?
—
Reply to this email directly, view it on GitHub[#91 (comment)], or unsubscribe[https://github.com/notifications/unsubscribe-auth/AAEQZ3CVPXCVDO4CG252KP3YQWGYVAVCNFSM6AAAAAA644A5OOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJTGM3TAMBWGA].
You are receiving this because you were mentioned.
[Tracking image][https://github.com/notifications/beacon/AAEQZ3BIF64YTHZQC6V4KNLYQWGYVA5CNFSM6AAAAAA644A5OOWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTSBO24Y.gif]
|
"buy" chart is also bugged around midnight.
I run the PR code on my Homeassistant. It works well in general, good performance in general. I have one issue: sensor.homekit.grid is always positive and does not change sign depending on if the power is imported or exported. Is there an easy way to fix? |
really looking forward to this PR is there further updates please? |
sems |
GridStatus should be used to determine sign. |
Would it be possible to remove "HomeKit" naming from Home Assistant? With the big changes in this PR it will likely break backwards compatibility for most users anyway. I suggest remove HomeKit device and naming from HA and add all sensors to inverter device. The HomeKit naming is confusing and I guess most users have a non HomeKit smart meter. isHomKit from powerflow data should be used to determine if HomeKit sn should be set (if HomeKit sn is required at all?). |
] | ||
|
||
if "hasPowerflow" in data and data["hasPowerflow"] and "powerflow" in data: | ||
inverter_serial_number = get_home_kit_sn(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you should add check for data["powerflow"]["isHomKit"]. If it is false there is no HomeKit sn and name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This falls through to the next statement if you don't have a homekit and we just call it powerflow
if not has_existing_homekit_entity or inverter_serial_number is None:
inverter_serial_number = "powerflow"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that will still create the homekit device right? It is confusing.
device_info, | ||
f"{inverter_serial_number}-grid", | ||
f"HomeKit Grid", | ||
["powerflow", "grid"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gridStatus should be used to determine buy/sell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what the possible values of gridStatus
are and what they mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gridStatus seems to not work, it is always 1 for me. I have pmeter in the inverter device though and that shows same value as grid from powerflow but with sign. pmeter is negative when buying and positive when selling. Note that I don't have homekit smart meter, I have GM3000 smart meter.
device_info, | ||
f"{inverter_serial_number}-battery", | ||
f"HomeKit Battery", | ||
["powerflow", GOODWE_SPELLING.battery], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
betteryStatus should be used to determine charging/discharging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what the possible values of betteryStatus
are and what they mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-1 = Discharging
0 = Off (100% soc and PV production for example)
1 = Charging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we do
batteryStatus = 0
battery = 10 // kwh
return battery * batteryStatus // 0
batteryStatus = 1
battery = 10 // kwh
return battery * batteryStatus // 10
batteryStatus = -1
battery = 10 // kwh
return battery * batteryStatus // -10
if we do the same for grid it should also work for you where it's always 1 but your grid value includes the sign
e.g.
gridStatus = 1
grid= -10 // kwh
return battery * batteryStatus // -10
Signed-off-by: David Christen <[email protected]>
Use new constants for units
@Brumhilde can you test changes to the sign of load, grid for you use case. |
Just started my venture into HA after getting solar and this is my first integration so apologies if this is an obvious answer. I have my grid sensor that is also positive. I can see that grid status swings between positive and negative as per buying/selling from the grid. But how can I get a negative result to display somewhere in a sensor so I can use it for a live dashboard? |
any update on this PR please? |
Sorry, no update from me due to lack of time. |
This branch currently fulfills my use case, so is done from my perspective. |
Great. Unfortunately I don't have time to review the branch properly. |
any news for the beta release please? |
It seems I can't create a release since the branch is not on my repo. And I currently don't have time/energy to look into it more. You can always manually deploy the files in your |
@L-four, just a quick PR with your fork.