Skip to content

Commit

Permalink
feat: Add custom sensors for KSTAR
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Oct 6, 2024
1 parent 9ac02b9 commit 8560dbe
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions custom_components/solarman/inverter_definitions/kstar_hybrid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,73 @@ parameters:
registers: [3301]
icon: "mdi:battery-plus-variant"

- group: Losses
update_interval: 30
items:
- name: Today Losses
alt: Daily Losses
friendly_name: Today's Losses
description: Includes today's consumption of the inverter device itself as well AC/DC conversion losses
update_interval: 30
class: "energy"
state_class: "total_increasing"
ensure_increasing:
uom: "kWh"
rule: 1
digits: 1
scale: 0.1
registers: [3109, 3036, 3294, 3116, 3147, 0x0054]
uint: enforce
sensors:
- registers: [3109]
- registers: [3036]
- registers: [3294]
- operator: subtract
registers: [3116]
- operator: subtract
registers: [3147]
- operator: subtract
registers: [3301]

- name: Total Losses
description: Includes total consumption of the inverter device itself as well AC/DC conversion losses
update_interval: 30
class: "energy"
state_class: "total_increasing"
ensure_increasing:
uom: "kWh"
rule: 3
digits: 1
scale: 0.1
registers:
[
3115,
3114,
3042,
3041,
3293,
3292,
3122,
3121,
3153,
3152,
3300,
3299,
]
uint: enforce
sensors:
- registers: [3115, 3114]
- registers: [3042, 3041]
- registers: [3293, 3292]
- operator: subtract
registers: [3122, 3121]
- operator: subtract
registers: [3153, 3152]
- operator: subtract
registers: [3300, 3299]
validation:
min: 1

- group: Inverter Information
items:
- name: "Inverter Working Mode"
Expand Down Expand Up @@ -816,3 +883,21 @@ parameters:
rule: 1
registers: [3144]
icon: "mdi:home-lightning-bolt"

- name: "Power losses"
description: Includes consumption of the inverter device itself as well AC/DC conversion losses
class: "power"
state_class: "measurement"
uom: "W"
rule: 1
digits: 0
registers: [3024, 3025, 3065, 3126]
uint: enforce
sensors:
- registers: [3024]
- registers: [3025]
- signed:
registers: [3065]
- operator: subtract
signed:
registers: [3126]

30 comments on commit 8560dbe

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

Hey @frsantos, can you please check it for me?

@frsantos
Copy link
Contributor

@frsantos frsantos commented on 8560dbe Oct 6, 2024

Choose a reason for hiding this comment

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

Hey @frsantos, can you please check it for me?

Hi @davidrapan

I get these errors in the logs:

2024-10-06 12:59:24.999 DEBUG (MainThread) [custom_components.solarman] async_setup_entry({'created_at': '2024-08-28T19:57:40.207144+00:00', 'data': {'name': 'KSTAR', 'inverter_discovery': True, 'inverter_host': '192.168.1.134', 'inverter_serial': 2355XXXXXX, 'inverter_port': 8899, 'inverter_mb_slave_id': 1, 'inverter_passthrough': False, 'lookup_file': 'kstar_hybrid.yaml', 'battery_nominal_voltage': 48, 'battery_life_cycle_rating': 6000}, 'discovery_keys': {}, 'disabled_by': None, 'domain': 'solarman', 'entry_id': '01J6D91CZFTSW8Z5JXA2TJG2KE', 'minor_version': 1, 'modified_at': '2024-08-28T19:57:40.207151+00:00', 'options': {'name': 'KSTAR', 'inverter_discovery': True, 'inverter_host': '192.168.1.134', 'inverter_serial': 2355XXXXXX, 'inverter_port': 8899, 'inverter_mb_slave_id': 1, 'inverter_passthrough': False, 'lookup_file': 'kstar_hybrid.yaml', 'battery_nominal_voltage': 48, 'battery_life_cycle_rating': 6000}, 'pref_disable_new_entities': False, 'pref_disable_polling': False, 'source': 'user', 'title': 'KSTAR', 'unique_id': None, 'version': 1})
2024-10-06 12:59:24.999 DEBUG (MainThread) [custom_components.solarman.discovery] discover
2024-10-06 12:59:25.000 DEBUG (MainThread) [custom_components.solarman.discovery] _discover_all: Broadcasting on 192.168.1.134
2024-10-06 12:59:25.000 DEBUG (MainThread) [custom_components.solarman.discovery] _discover
2024-10-06 12:59:25.011 DEBUG (MainThread) [custom_components.solarman.discovery] _discover: [192.168.1.134, 289C6E8569EC, 2355XXXXXX]
2024-10-06 12:59:25.308 DEBUG (MainThread) [custom_components.solarman.parser] Defaults for update_interval: 60, code: 4, min_span: 25, digits: 6
2024-10-06 12:59:25.309 DEBUG (MainThread) [custom_components.solarman.api] {'connections': {('mac', '28:9c:6e:85:69:ec')}, 'identifiers': {('solarman', 2355XXXXXX)}, 'name': 'KSTAR', 'manufacturer': 'KSTAR', 'model': 'Hybrid Inverter', 'serial_number': 2355XXXXXX}
2024-10-06 12:59:25.309 DEBUG (MainThread) [custom_components.solarman] async_setup: coordinator.async_config_entry_first_refresh
2024-10-06 12:59:25.310 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] Scheduling 7 query requests. #0
2024-10-06 12:59:25.310 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] Querying 0084 - 0084 | 0x0054 - 0x0054 # 001 ...
2024-10-06 12:59:25.311 INFO (MainThread) [custom_components.solarman.api] [2355XXXXXX] Connecting to 192.168.1.134:8899
2024-10-06 12:59:25.322 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] SENT: a5 17 00 10 45 82 00 e8 56 61 8c 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 04 00 54 00 01 70 1a ff 15
2024-10-06 12:59:25.411 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] RECD: a5 13 00 10 15 82 90 e8 56 61 8c 02 01 eb bd 99 38 3f 26 00 00 a2 af 68 2e 01 84 02 c2 c1 47 15
2024-10-06 12:59:25.412 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] Querying 0084 - 0084 | 0x0054 - 0x0054 # 001 failed. [IllegalDataAddressError:  The data address received in the request is not an allowable address for
    the server.
    ]
2024-10-06 12:59:25.613 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] Querying 0084 - 0084 | 0x0054 - 0x0054 # 001 attempts left: 4
2024-10-06 12:59:25.613 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] SENT: a5 17 00 10 45 83 00 e8 56 61 8c 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 04 00 54 00 01 70 1a 00 15
2024-10-06 12:59:25.661 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] RECD: a5 13 00 10 15 83 91 e8 56 61 8c 02 01 ec bd 99 38 3f 26 00 00 a2 af 68 2e 01 84 02 c2 c1 4a 15
2024-10-06 12:59:25.661 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] Querying 0084 - 0084 | 0x0054 - 0x0054 # 001 failed. [IllegalDataAddressError:  The data address received in the request is not an allowable address for
    the server.
    ]
2024-10-06 12:59:26.063 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] Querying 0084 - 0084 | 0x0054 - 0x0054 # 001 attempts left: 3
2024-10-06 12:59:26.063 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] SENT: a5 17 00 10 45 84 00 e8 56 61 8c 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 04 00 54 00 01 70 1a 01 15
2024-10-06 12:59:26.161 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] RECD: a5 13 00 10 15 84 92 e8 56 61 8c 02 01 ec bd 99 38 3f 26 00 00 a2 af 68 2e 01 84 02 c2 c1 4c 15
2024-10-06 12:59:26.162 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] Querying 0084 - 0084 | 0x0054 - 0x0054 # 001 failed. [IllegalDataAddressError:  The data address received in the request is not an allowable address for
    the server.
    ]
2024-10-06 12:59:26.764 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] Querying 0084 - 0084 | 0x0054 - 0x0054 # 001 attempts left: 2
2024-10-06 12:59:26.764 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] SENT: a5 17 00 10 45 85 00 e8 56 61 8c 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 04 00 54 00 01 70 1a 02 15
2024-10-06 12:59:26.861 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] RECD: a5 13 00 10 15 85 93 e8 56 61 8c 02 01 ed bd 99 38 40 26 00 00 a2 af 68 2e 01 84 02 c2 c1 50 15
2024-10-06 12:59:26.862 DEBUG (MainThread) [custom_components.solarman.api] [2355XXXXXX] Querying 0084 - 0084 | 0x0054 - 0x0054 # 001 failed. [IllegalDataAddressError:  The data address received in the request is not an allowable address for

I just replaced the yml file, no version update (running 24.10.04 right now), do I need to update the code? I don't think there is any change related to this?

@frsantos
Copy link
Contributor

@frsantos frsantos commented on 8560dbe Oct 6, 2024

Choose a reason for hiding this comment

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

Can it be this 0x0054?

    registers: [3109, 3036, 3294, 3116, 3147, 0x0054]

Changing it to 3301 seems to not fail. Waiting to get some result...

How can I test the values are correct?

@davidrapan
Copy link
Owner Author

@davidrapan davidrapan commented on 8560dbe Oct 6, 2024

Choose a reason for hiding this comment

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

Sure it's a typo: fix: Registers in custom sensor for KSTAR 😉

Thanks.

How can I test the values are correct?

Try to calculate them yourself? Formulas are on the first wiki page.

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

How can I test the values are correct?

Try to calculate them yourself? Formulas are on the first wiki page.

Yes, I was thinking if I could just compare to any calculation HA does by itself.

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

🤔

With Power losses no, that's brand new, but for example Today's Losses + Today's Load Consumption should show the value which is in the Energy Dashboard.

@frsantos
Copy link
Contributor

@frsantos frsantos commented on 8560dbe Oct 6, 2024

Choose a reason for hiding this comment

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

Sure it's a typo: fix: Registers in custom sensor for KSTAR 😉

After 2 hours, it's still "unknown"

Image

I'll check later

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

And what about those other two sensors?

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

Same

Image

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

It looks like there is an error in the Power losses, should be like this:

      - name: "Power losses"
        description: Includes consumption of the inverter device itself as well AC/DC conversion losses
        class: "power"
        state_class: "measurement"
        uom: "W"
        rule: 1
        digits: 0
        registers: [3024, 3025, 3065, 3126]
        uint: enforce
        sensors:
          - signed:
            registers: [3024]
          - signed:
            registers: [3025]
          - signed:
            registers: [3065]
          - operator: subtract
            signed:
            registers: [3126]

But I don't see anything wrong with the other two... 🤔 And your values looks like they should produce valid results... what the heck...

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

Which version you have installed though?

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

Which version you have installed though?

I just replaced the yml file, no version update (running 24.10.04 right now), do I need to update the code? I don't think there is any change related to this?

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

I was only asking if you for example don't run some older version but the most recent one is enough.

Still has no idea what it does not work. Entity descriptions fit the other sensors, I checked many times already....

Does the PV Power sensors work?

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, yesterday was already dark, but now it reports data

Image

@davidrapan
Copy link
Owner Author

@davidrapan davidrapan commented on 8560dbe Oct 7, 2024

Choose a reason for hiding this comment

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

I don't see there custom sensor PV Power. Only PV1/2 Power.

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah sorry, you meant the custom. Yes, it works

Image

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

Logs seem to be OK, and I think all registers are requested for each custom sensor

home-assistant_solarman_2024-10-07T11-37-38.764Z.log

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

I think I can see what's going on... for example for power losses registers are not all in the same request... Register 3126 is then requested in new one...

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, so the calculation is done per request, and not at the end?

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

Exactly, it's because the calculation should be done over data which are in sync and that can't be ensured over multiple requests.

I'll have to think about it some more.

@davidrapan
Copy link
Owner Author

@davidrapan davidrapan commented on 8560dbe Oct 7, 2024

Choose a reason for hiding this comment

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

@githubDante? I how bad it is to do some calculations over data from separate modbus request responses?

@githubDante
Copy link

Choose a reason for hiding this comment

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

I don't think that's bad at all. 200-300ms between the responses won't make any difference.

@davidrapan
Copy link
Owner Author

@davidrapan davidrapan commented on 8560dbe Oct 7, 2024

Choose a reason for hiding this comment

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

Okay then! Thanks!

So I will change (soon) how are responses processed (to processing them all in bulk) and that should solve it. 😉

I'll let you know when it's done.

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

refactor: Processing all modbus responses in bulk

Should solve those missing results from calculation across multiple responses from modbus.

It will proly need some more optimizations here and there but it's tested (and already deployed in production) and should retain functionality in other areas as expected.

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems it works now

Image

Out of curiosity, how do you compare in these figures? 6% of the total energy movement.

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

Out of curiosity, how do you compare in these figures? 6% of the total energy movement.

You are asking if the results makes sense?

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

The total loss figure matches , but yes, I'm asking if a 6% total loss is a normal figure for you? Not sure if that's normal, low or high.

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

Deye SG04LP3 daily losses are from 2,4 kWh (day with almost no sun) to up to 6 kWh (very sunny day, in this particular location with production around 60 kWh).

@davidrapan
Copy link
Owner Author

Choose a reason for hiding this comment

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

And to give you direct answer. To my knowledge the expected conversion efficiency of PV is I think around 93% so yes, it matches the expectations.

@frsantos
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I thought it was around that. Just to check if I should call the installer or not.

Please sign in to comment.