wills106 / homeassistant-solax-modbus

SolaX Power Modbus custom_component for Home Assistant (Supports some AlphaESS, Growatt, Sofar, Solinteg, Solis, SRNE, Swatten)
327 stars 107 forks source link

Support writing of Charger Times to the Inverter #27

Closed wills106 closed 2 years ago

wills106 commented 2 years ago

The problem though is that I have not worked out an easy way to program them within HA. The first problem is that for built in Integrations (custom_components) there is no equivalent to input.datetime so I would either need a separate number entry for hours and mins for each time block. So a total of 8 number.solax Which would result in quite a messy user interface.

The other option is to look into how I monitor a user created input.date_time Which would either need the user to follow an exact naming convention, or for the option to put in the various input.date_time into the initial Integration Configuration page. So it knows what to monitor.

Then to complicate things more SolaX decided that while you read hours as a single 16bit entry and minutes as another 16bit entry, you program both the hours and minutes for a timeslot as a single 16bit number. Using hi 8bit for mins and the low 8bit as the hours.

So if you want to program the Start Time of Slot 1 you need to do the following for 09:10 am

Hbyte = 10 Lbyte = 9 value = Hbyte << 8 | Lbyte;

Which gives you the number of 2569 which is what you program to the corresponding register.

wills106 commented 2 years ago

Release 0.4.4 Starts to partially address this issue, but in a crude hard encoded way.

wills106 commented 2 years ago

Just checked over the docs. Gen2 & Gen3 uses Lo for hours and Hi for mins. But Gen4 has swapped it to Lo for mins and Hi for hours...

Will need a separate "TIME_OPTIONS" for Gen4 ie "TIME_OPTIONS_Gen4"

infradom commented 2 years ago

FYI: I also intended to add time entry fields (see TIME_TYPES_G4), and was intending so copy some of the work done ly Quitschibo https://community.home-assistant.io/u/Quitschibo described in this thread : https://community.home-assistant.io/t/add-device-of-different-domain-in-custom-component/253189/19 But I ran out of time and postponed my effort.

Jan

On Thu, Feb 24, 2022 at 9:43 AM wills106 @.***> wrote:

Just checked over the docs. Gen2 & Gen3 uses Lo for hours and Hi for mins. But Gen4 has swapped it to Lo for mins and Hi for hours...

Will need a separate "TIME_OPTIONS" for Gen4 ie "TIME_OPTIONS_Gen4"

— Reply to this email directly, view it on GitHub https://github.com/wills106/homsassistant-solax-modbus/issues/27#issuecomment-1049619118, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2B23UMY4UUR6AOZNKQVL3U4XVUTANCNFSM5O5UQK4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Jan Colpaert +32 478 882435

wills106 commented 2 years ago

It's only meant as a quick stop gap, I'll do the same for Gen4 for the time being. At least we have partial functionality even if it's in 15min chunks. Should cover most use cases?

I guess it depends if the HA mods would allow this method in an official Integration? Hopefully date_time will end up as a proper entity as some point in the near future. I know it's been asked a number of times in the Dev Chat on Discord.

infradom commented 2 years ago

Thanks, yes, indeed this should cover most cases !

wills106 commented 2 years ago

Do your times (discharger_start_time_2 etc) report back as 01:05 or 1:5?

I had to pad out the ones for Gen2 / Gen3 as the Inverter's return the values without the leading zero.

infradom commented 2 years ago

Not sure I understand your question well, in the code I provided, I added a function Gen4Timestrig that formats time with leading zero as 01:05

def Gen4Timestring(numb): h = numb % 256 m = numb >> 8 return f"{h:02d}:{m:02d}"

Hope this answers your question.

On Thu, Feb 24, 2022 at 1:27 PM wills106 @.***> wrote:

Do your times (discharger_start_time_2 etc) report back as 01:05 or 1:5?

I had to pad out the ones for Gen2 / Gen3 as the Inverter's return the values without the leading zero.

— Reply to this email directly, view it on GitHub https://github.com/wills106/homsassistant-solax-modbus/issues/27#issuecomment-1049809382, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2B23SYWU5CJYZQS4PNX2TU4YP23ANCNFSM5O5UQK4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

-- Jan Colpaert +32 478 882435

infradom commented 2 years ago

So the Gen4 encodes hour and minutes in the same 16bit word, whereas previous generations used 2 separate words

On Thu, Feb 24, 2022 at 1:52 PM Jan Colpaert @.***> wrote:

Not sure I understand your question well, in the code I provided, I added a function Gen4Timestrig that formats time with leading zero as 01:05

def Gen4Timestring(numb): h = numb % 256 m = numb >> 8 return f"{h:02d}:{m:02d}"

Hope this answers your question.

On Thu, Feb 24, 2022 at 1:27 PM wills106 @.***> wrote:

Do your times (discharger_start_time_2 etc) report back as 01:05 or 1:5?

I had to pad out the ones for Gen2 / Gen3 as the Inverter's return the values without the leading zero.

— Reply to this email directly, view it on GitHub https://github.com/wills106/homsassistant-solax-modbus/issues/27#issuecomment-1049809382, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2B23SYWU5CJYZQS4PNX2TU4YP23ANCNFSM5O5UQK4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

-- Jan Colpaert +32 478 882435

-- Jan Colpaert +32 478 882435

wills106 commented 2 years ago

It's annoying they keep switching things. Like the above mentioned flip of Hi and Lo for the hours and mins.

I have added in the Gen4 times & selects. Hopefully they are correct. I have not added it to a release yet. Could you let me know if they look correct?

infradom commented 2 years ago

I am not convinced that Gen4 is different from Gen2/3 in the byte sequence My Gen4Timesting function might be wrong however .. but that is not my feeling as the Solax GUI shows the same time as my sensor Of course Gen2/Gen3 allocate dedicated 16 bit words for hour and minutes, wheraas Gen4 encodes them in one single 16bit word

def Gen4Timestring(numb): h = numb % 256 m = numb >> 8 return f"{h:02d}:{m:02d}"

On Thu, Feb 24, 2022 at 2:14 PM wills106 @.***> wrote:

It's annoying they keep switching things. Like the above mentioned flip of Hi and Lo for the hours and mins.

I have added in the Gen4 times & selects. Hopefully they are correct. I have not added it to a release yet. Could you let me know if they look correct?

— Reply to this email directly, view it on GitHub https://github.com/wills106/homsassistant-solax-modbus/issues/27#issuecomment-1049847435, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2B23VPNDSEOLK5V665CQLU4YVKFANCNFSM5O5UQK4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

-- Jan Colpaert +32 478 882435

wills106 commented 2 years ago

So potentially TIME_OPTIONS_GEN4 isn't needed?

infradom commented 2 years ago

Indeed, that is what I believe, I am still verifying, It is unclear how you demultiplex the values returned from the select into two different 16 bit integers for Gen2/Gen3

On Thu, Feb 24, 2022 at 2:42 PM wills106 @.***> wrote:

So potentially TIME_OPTIONS_GEN4 isn't needed?

— Reply to this email directly, view it on GitHub https://github.com/wills106/homsassistant-solax-modbus/issues/27#issuecomment-1049872815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2B23XQD7CPWHXSYD2IXB3U4YYSXANCNFSM5O5UQK4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

-- Jan Colpaert +32 478 882435

infradom commented 2 years ago

please forget my last comment, write operations are similar ... unlike read

I am still verifying

On Thu, Feb 24, 2022 at 2:43 PM Jan Colpaert @.***> wrote:

Indeed, that is what I believe, I am still verifying, It is unclear how you demultiplex the values returned from the select into two different 16 bit integers for Gen2/Gen3

On Thu, Feb 24, 2022 at 2:42 PM wills106 @.***> wrote:

So potentially TIME_OPTIONS_GEN4 isn't needed?

— Reply to this email directly, view it on GitHub https://github.com/wills106/homsassistant-solax-modbus/issues/27#issuecomment-1049872815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2B23XQD7CPWHXSYD2IXB3U4YYSXANCNFSM5O5UQK4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

-- Jan Colpaert +32 478 882435

-- Jan Colpaert +32 478 882435

infradom commented 2 years ago

I would not drop it yet, I will test first and see how the values are shown in the solax GUI I am not sure if the documentation is correct ....

Give me a half an hour to pull your version into my system ...

Jan

On Thu, Feb 24, 2022 at 2:42 PM wills106 @.***> wrote:

So potentially TIME_OPTIONS_GEN4 isn't needed?

— Reply to this email directly, view it on GitHub https://github.com/wills106/homsassistant-solax-modbus/issues/27#issuecomment-1049872815, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2B23XQD7CPWHXSYD2IXB3U4YYSXANCNFSM5O5UQK4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

-- Jan Colpaert +32 478 882435

wills106 commented 2 years ago

I am not sure if the documentation is correct ....

Wouldn't be the first time

infradom commented 2 years ago

I did a quick test with your current version (different TIMES_Gen4) and it seems to behave coorectly: If I load charger_end_time1 with valhue 01:15, it also displays this way in the solax GUI So your current interpretation seems to be right

Jan

On Thu, Feb 24, 2022 at 2:51 PM wills106 @.***> wrote:

I am not sure if the documentation is correct ....

Wouldn't be the first time

— Reply to this email directly, view it on GitHub https://github.com/wills106/homsassistant-solax-modbus/issues/27#issuecomment-1049880438, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC2B23VUKC2DOBJ2DP7OC5DU4YZUZANCNFSM5O5UQK4A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

-- Jan Colpaert +32 478 882435

wills106 commented 2 years ago

Thanks for validating that.

Once I have confirmation that Gen2 works the same as Gen3 I'll release it all as 0.4.5

AviadorLP commented 2 years ago

Since you are changing times to full digits can you do that to the sensor.solax_rtc please ? already done the change to your code but don't know if it affects anything else.

        rtc_seconds = str(decoder.decode_16bit_uint())
        self.data["rtc_seconds"] = rtc_seconds

        rtc_minutes = str(decoder.decode_16bit_uint())
        rtc_hours = str(decoder.decode_16bit_uint())
        rtc_days = str(decoder.decode_16bit_uint())
        rtc_months = str(decoder.decode_16bit_uint())
        rtc_years = str(decoder.decode_16bit_uint())

        self.data["rtc"] = f"{rtc_hours.zfill(2)}:{rtc_minutes.zfill(2)}:{rtc_seconds.zfill(2)} {rtc_days.zfill(2)}/{rtc_months.zfill(2)}/{rtc_years.zfill(2)}"
wills106 commented 2 years ago

Closing down due to being on the Todo List #37 for further investigation.