davidrapan / ha-solarman

⚡ Solarman Stick Logger integration for 🏠 Home Assistant
MIT License
115 stars 25 forks source link

feat: Update KStar inverter file to new integration #71

Closed frsantos closed 3 months ago

frsantos commented 3 months ago

I have been testing the KStar Hybrid inverter for some days now, and it works perfect. In this PR I update the KStar Hybrid definition file to the new format:

I have a question regarding custom sensors, though: the KStar inverter has the versions stored in single registers as numbers, and to get a readable value, I need to perform some mathematical operations on it:

ARM Version Number and DSP Version Number are a single register each, containing the "Version Number" on the first byte and the "Testing version number" on the second byte. The modbus documentation says "10 refer to V1.0", and a note "the test version number range is 0-99. If the DSP1 version number is v1.0, the DSP1 test version number is 2, and the DSP1 full version number is v1.0.2".

I came up with a helper to calculate the version from the number in the register, with the following template:

{%- set version = states('sensor.kstar_arm_version_number')|int %}
{%- set xy = (version / 256) | int %}
{%- set x = (xy / 10) | int %}
{%- set y = xy % 10 %}
{%- set z = (version % 256) | int %}
V{{x}}.{{y}}.{{z}}

So, the number 5899 gives the version V2.3.11.

Is there any way of adding complex operations in a custom sensor, apart from addition and subtraction, like the template above?

davidrapan commented 3 months ago

Is there any way of adding complex operations in a custom sensor, apart from addition and subtraction, like the template above?

Not yet. Would be awesome though! At first I used 'eval' with defined equations and parameters but it has serious security implications so I decided to go the hard way which means that it's not really that flexible. :-/ ...yet!

frsantos commented 3 months ago

Is there any way of adding complex operations in a custom sensor, apart from addition and subtraction, like the template above?

Not yet. Would be awesome though! At first I used 'eval' with defined equatins and parameters but it has serious security implications so I decided to go the hard way which means that it's not really that flexible. :-/ ...yet!

Not sure how templates are implemented in HA, but could we use the same jinja2 templates as in a helper? I suppose templating in HA is already considering all security implications.

davidrapan commented 3 months ago

Yes I was looking into utilizations of Template Sensors directly in the integration and would love to do it that way but I'm not yet well educated in that area and not sure how it's supposed to be done. :-/ ...yet!

davidrapan commented 3 months ago

Add there min_span: 55 into default section. 😉