mkaiser / Sungrow-SHx-Inverter-Modbus-Home-Assistant

Sungrow SH Integration for Home Assistant for SH3K6, SH4K6, SH5K-20, SH5K-V13, SH3K6-30, SH4K6-30, SH5K-30, SH3.RS, SH3.6RS, SH4.0RS, SH5.0RS, SH6.0RS, SH5.0RT, SH6.0RT, SH8.0RT, SH10RT, SH5.0RT-20, SH6.0RT-20, SH8.0RT-20, SH10RT-20, SH5.0RT-V112, SH6.0RT-V112, SH8.0RT-V112, SH10RT-V112, SH5.0RT-V122, SH6.0RT-V122, SH8.0RT-V122, SH10RT-V122, SH4.6R
328 stars 86 forks source link

Fixed some issues and added some sensors #47

Closed Louisbertelsmann closed 1 year ago

Louisbertelsmann commented 1 year ago

I wanted to set up the Energy Dashboard and I couldn't add some entities, because they lacked last_reset. I fixed all of the entities that didn't work and added the sensors: Monthly direct energy consumption Yearly direct energy consumption Monthly PV energy yields Yearly PV energy yields Monthly exported energy from PV Yearly exported energy from PV

I added unique ids to the sensors I added.

mkaiser commented 1 year ago

I wanted to set up the Energy Dashboard and I couldn't add some entities, because they lacked last_reset.

I am curious, what did you want to add to the energy dashboard?

Louisbertelsmann commented 1 year ago

I wanted to add those daily Sensors to the premade energy dashboard. That wasn't possible, because it needs last_reset and that isn't Provided by stateclass measurement. It needs to be total_increasing. Will fix it tomorrow. If you need any more help, you can just ask.

mkaiser commented 1 year ago

My Energy Dashboard configuration dialogue looks like this. I only see the option for total import/export energy. Where can you set daily sensors?

image

Louisbertelsmann commented 1 year ago

I just added them in the corresponding categories. For that, you need last_reset. That isn‘t provided by measurement, only by total(_increasing). I‘m not at home right now, so I‘m on my work iPad. Am fixing your requested changes right now. 45FC8BE2-7295-42D2-80C6-C3D9FEF6D89D 8C458250-390E-41A6-A7EE-1832F1C14163

dylan09 commented 1 year ago

I am also using the total_... sensors for my energy dashboard. Until now everything works. I see my daily values. HA should do the work at midnight and calculate the relevant values.

Louisbertelsmann commented 1 year ago

Didn‘t know it does that. That‘s great!

mkaiser commented 1 year ago

aaah, you used the daily sensors for the energy dashboard. Was really confused, because it was working fine for me so far.

I guess, the README needs some clarification.

Will merge your changes - thank you!

Louisbertelsmann commented 1 year ago

Just read through some old pull requests. I think I‘ve got a new way to set the slave ID outside of secrets.yaml. Wouldn‘t it be possible to add an input_numer that goes from 1 to 247(i think) and sets the slave variable for every sensor at once? That would mean that you can remove configuration from secrets.yaml, because the ip_address and the port only needs to be set once and that‘s easily accessible. That would also be possible to do by an input_number or input_text if you want to.

mkaiser commented 1 year ago

linked your suggestion to

https://github.com/mkaiser/Sungrow-SHx-Inverter-Modbus-Home-Assistant/issues/38

otherwise it will get lost :)

Louisbertelsmann commented 1 year ago

I don‘t know if it works for you, but I just noticed that the new sensors I added don‘t report anything. Would you mind checking it? They all just show as 0,0kWh… I checked your „daily battery charge from pv“ read-out and the address you gave it is 13011. In the newest modbus list from sungrow it‘s 6744-6774. 13011 is export power.

dylan09 commented 1 year ago

Be carefull with modbus address and register. Daily battery charge energy from PV is register(address) 13012 in Sungrow documentation. In modbus.yaml you have to use 13011 (13012 - 1).

And address 6744-6774 seems to be 31 registers which are holding 1 value per day of month. Maybe you could try if you could get data from this registers.

If I am right with my calculation for yesterday (25. day) you have to read reg 6768 (in modbus.yaml 6767).

You could also find 12 monthly and 20 yearly registers in the documentation.

Louisbertelsmann commented 1 year ago

I thought something like that would be the case, but I wanted to know for Sure. Unfortunately sungrow doesn't offer a real monthly read-out. Someone on the photovoltaikforum wrote something about undocumented addresses. Does Someone have a list like that? I also found another address list on the io Broker forum, but I didn't have the time to Look through it. Will Do it this evening.

Louisbertelsmann commented 1 year ago

Have you got any clue on how those yearly generation registers are laid out? I just read them with QModMaster and two inputs have got anything in them. (That makes sense since I only installed it in early september. address 6264 converted to decimal is 11122 (1112.2kWh) and address 6266 (this year) converted to decimal is 1189 (118.9kWh) which makes sense, because that adds up to the total pv generation. The rest of the registers is either 0000000000000000 or 1111111111111111. I think that there is one empty register between all of the filled ones. If that's the case there are 8 registers before 2023, so when my math is correct it should've started in the year 2015. When that's correct, I would read out all registers and create an automation that writes the current year into it's own template sensor, if possible. grafik

Louisbertelsmann commented 1 year ago

Nevermind. The automation that changes the year would need extra setup. I like the idea of just copy-pasting something and not needing a lot of setup. If you've got an idea, I would love to hear that.

Louisbertelsmann commented 1 year ago

Ok, I think I just found a way. With {{ now().year }} I can read the current year and based on that I can change which sensor the template uses.

Louisbertelsmann commented 1 year ago

I was stupid. It's a 32-bit integer and one register only shows 16-bits.

Louisbertelsmann commented 1 year ago

Found a way to implement it. Found the "command" {{ now().year }}. This is the template I came up with: {{ states('sensor.total_pv_generationof{{ now().year }}') }} The name of the sensors is total_pv_generation_of_2023 (for example) and that should work fine. We'll see in 340 days.

Louisbertelsmann commented 1 year ago

works now. {% if (states('sensor.current_year') | int(default=0)) == 2019 %} {{ states('sensor.total_pv_generation_of_2019') }} {% elif (states('sensor.current_year') | int(default=0)) == 2020 %} {{ states('sensor.total_pv_generation_of_2020') }} {% elif (states('sensor.current_year') | int(default=0)) == 2021 %} {{ states('sensor.total_pv_generation_of_2021') }} {% elif (states('sensor.current_year') | int(default=0)) == 2022 %} {{ states('sensor.total_pv_generation_of_2022') }} {% elif (states('sensor.current_year') | int(default=0)) == 2023 %} {{ states('sensor.total_pv_generation_of_2023') }} {% elif (states('sensor.current_year') | int(default=0)) == 2024 %} {{ states('sensor.total_pv_generation_of_2024') }} {% elif (states('sensor.current_year') | int(default=0)) == 2025 %} {{ states('sensor.total_pv_generation_of_2025') }} {% elif (states('sensor.current_year') | int(default=0)) == 2026 %} {{ states('sensor.total_pv_generation_of_2026') }} {% elif (states('sensor.current_year') | int(default=0)) == 2027 %} {{ states('sensor.total_pv_generation_of_2027') }} {% elif (states('sensor.current_year') | int(default=0)) == 2028 %} {{ states('sensor.total_pv_generation_of_2028') }} {% elif (states('sensor.current_year') | int(default=0)) == 2029 %} {{ states('sensor.total_pv_generation_of_2029') }} {%endif%}

Louisbertelsmann commented 1 year ago

grafik