davidrapan / ha-solarman

⚑ Solarman Stick Logger integration for 🏠 Home Assistant
MIT License
58 stars 16 forks source link

Can we keep last known data after device disconnects? #87

Open CrazyUs3r opened 1 month ago

CrazyUs3r commented 1 month ago

Can you change something so that when you disconnect it will continue to be displayed.

davidrapan commented 1 month ago

But not everyone wants that behavior so I'm gonna have to think about it. πŸ˜‰

CrazyUs3r commented 1 month ago

Here you can see what me Problem is to 0 go it from the inverter this not direct a problem from the py

Screenshot_20240816_193103_Home Assistant

CrazyUs3r commented 1 month ago

2024-08-16 20:36:56.897 ERROR (MainThread) [custom_components.solarman.coordinator] Timeout fetching solarmanm80 data 2024-08-16 20:39:58.335 ERROR (MainThread) [custom_components.solarman.coordinator] Error fetching solarmanm80 data: [3907049102] Querying 192.168.178.226:8899 failed. 2024-08-16 20:48:31.958 WARNING (MainThread) [custom_components.solarman.api] [3907049102] Querying (0 - 112) failed. #0 [NoSocketAvailableError: Cannot open connection to 192.168.178.226] 2024-08-16 20:48:32.158 DEBUG (MainThread) [custom_components.solarman.api] [3907049102] Querying attempts left: 4 2024-08-16 20:48:32.158 INFO (MainThread) [custom_components.solarman.api] [3907049102] Connecting to 192.168.178.226:8899 2024-08-16 20:48:35.221 WARNING (MainThread) [custom_components.solarman.api] [3907049102] Querying (0 - 112) failed. #0 [NoSocketAvailableError: Cannot open connection to 192.168.178.226] 2024-08-16 20:48:35.623 DEBUG (MainThread) [custom_components.solarman.api] [3907049102] Querying attempts left: 3 2024-08-16 20:48:35.623 INFO (MainThread) [custom_components.solarman.api] [3907049102] Connecting to 192.168.178.226:8899 2024-08-16 20:48:38.678 WARNING (MainThread) [custom_components.solarman.api] [3907049102] Querying (0 - 112) failed. #0 [NoSocketAvailableError: Cannot open connection to 192.168.178.226] 2024-08-16 20:48:39.278 DEBUG (MainThread) [custom_components.solarman.api] [3907049102] Querying attempts left: 2 2024-08-16 20:48:39.278 INFO (MainThread) [custom_components.solarman.api] [3907049102] Connecting to 192.168.178.226:8899 2024-08-16 20:48:42.390 WARNING (MainThread) [custom_components.solarman.api] [3907049102] Querying (0 - 112) failed. #0 [NoSocketAvailableError: Cannot open connection to 192.168.178.226] 2024-08-16 20:48:43.191 DEBUG (MainThread) [custom_components.solarman.api] [3907049102] Querying attempts left: 1 2024-08-16 20:48:43.191 INFO (MainThread) [custom_components.solarman.api] [3907049102] Connecting to 192.168.178.226:8899 2024-08-16 20:48:46.293 WARNING (MainThread) [custom_components.solarman.api] [3907049102] Querying (0 - 112) failed. #0 [NoSocketAvailableError: Cannot open connection to 192.168.178.226] 2024-08-16 20:48:47.295 DEBUG (MainThread) [custom_components.solarman.api] [3907049102] Querying attempts left: 0, aborting. 2024-08-16 20:48:47.295 DEBUG (MainThread) [custom_components.solarman.api] [3907049102] Request failed. [Previous State: Disconnected (-1)] 2024-08-16 20:48:47.295 INFO (MainThread) [custom_components.solarman.api] [3907049102] Disconnecting from 192.168.178.226:8899 2024-08-16 20:48:51.895 DEBUG (MainThread) [custom_components.solarman.api] [3907049102] Scheduling 1 query request. #0 2024-08-16 20:48:51.896 DEBUG (MainThread) [custom_components.solarman.api] [3907049102] Querying (0 - 112) ...

davidrapan commented 1 month ago

What am I looking at? Is that the time when your inverter goes offline?

CrazyUs3r commented 1 month ago

Yes the gaps or the 0 values ​​are during the night

gedger commented 1 month ago

I have had intermittent problems with connecting but my sensors go unavailable which is the correct state, HA displays it as a gap.

I discovered that the wireless stick was randomly connecting to another AP with a lower signal level which caused the connection issues. I solved the problem by creating a dedicated SSID on the nearest AP and then connecting to that. I still get occasional connection problems but have always found that powering off/on the Wi-Fi router and stick has solved them. I don't think the stick hardware is the best....

If the connection problem can't be solved by the integration then you can create a template sensor that checks the value and only updates when the value is valid i.e. available and not zero

davidrapan commented 1 month ago

I mean I could add configuration item which you toggle when you don'T want to loose the values after dc. BUT, I'm not sure if it won't bring more issues than it solves....

gedger commented 1 month ago

I have tried blocking the connection to my inverter many times and on all occasions I get a blank in the graph where the sensor went unavailable. None of the sensors went to Zero so I can't replicate the issue @CrazyUs3r is having on my system.

davidrapan commented 1 month ago

As far as I know this is happening only on some models which are using profiles deye_2mppt/4mppt and deye_string. So it's a "device specific thing" and it's complete BS!!!! But we were able to (thanks to our "amazing" integration πŸ˜†) mitigate it by applying validation (has to be > 0) on the values which were causing issues. It think @CrazyUs3r was able to figure it out first. πŸ‘

CrazyUs3r commented 1 month ago

@gedger What you mean is that you want to block your inverter from the internet. When I block mine, the values ​​are also only there, although I think the inverter sends the data to the Chinese server, but if it can't get there, it doesn't have the current time and just shows me nonsense.

davidrapan commented 1 month ago

Ho you are blocking it? Removing info about the server (Server A Setting, maybe also Optional Server Setting) on this page: http://{inverter_ip}/config_hide.html is not enough?

CrazyUs3r commented 1 month ago

First I blocked the connection in the fritzbox and later in adguard to see both variants. I had not yet deleted the connection under config_hiden

davidrapan commented 1 month ago

If you decide to try it let me know the result!

CrazyUs3r commented 1 month ago

If I lock everything then the only problem is that the device time is wrong, then the daily values, for example, are not reset but reading and writing the values ​​still works.

PV-Joe commented 1 month ago

I would be interested to be able to run the inverter completely local.

As far as I understand that is not possible cause of the time.

CrazyUs3r commented 1 month ago

I think I'll try the docker

https://github.com/Hypfer/deye-microinverter-cloud-free/tree/master/dummycloud

CrazyUs3r commented 1 month ago

I've just tested it locally but the docker doesn't offer any option to set the time, so the inverter gets the GMT time but I can see that the inverter gets its response to changing the time. Before: Screenshot_20240818_173737_Home Assistant After: Screenshot_20240818_173756_Home Assistant

gedger commented 1 month ago

Can't you write to the date/time registers via Solarman, that works for me.

CrazyUs3r commented 1 month ago

No. Your time does not fit the time setting because low year high hour and so on in the pdf

VoyteckPL commented 1 month ago

+1 for values visible when disconnected. Even optionally. I would rather have an option to choose if I want to see 0 or unknown.

gedger commented 1 month ago

No. Your time does not fit the time setting because low year high hour and so on in the pdf

I thought the Solarman stick was completely optional for inverters, well it is for Solis. I operated mine without the stick plugged in and instead used a direct RS485 connection to read/write all the values including setting the date and time. I can still do the same when the Solarman stick is plugged in. I only have the stick as Solis couldn't offer support without the remote connection.

+1 for values visible when disconnected. Even optionally. I would rather have an option to choose if I want to see 0 or unknown.

So if your inverter goes off-line or because there is a temporary connection problem then you want all the values to go to zero! You'll end up with the graph shown when this issue was raised which, in my view, is highly undesirable. Also what about monthly totals should they go to zero too? A alternative solution is to leave the values at whatever the last read value was. However, then all the values are in incorrect as they no longer reflect the true state of the inverter. That's why HA has the unavailable state, I can't connect to the inverter so I can't tell you the value hence it marks it as unavailable.

If anyone wishes for this behaviour then it can easily be achieved by using template sensors. The value can then be set to whatever you like. So my vote is to leave as is.

VoyteckPL commented 1 month ago

Ok maybe you are right! :) The problem is that I use current production sensor to calculate different things like excess power etc. I managed to create sensor which basically works like this - if unknown then = 0. Other sensors I don't actually use so this is not a big problem for me.

gedger commented 1 month ago

I think each user and each application may have a slightly different requirement so template sensors seem the way to go.

Another idea would be to add a new option to the validation. Min, Max, "Unavailable":value ?

VoyteckPL commented 1 month ago

I think some sensors have 0 during night so it could be shown as fake 0. :)

gedger commented 1 month ago

I do hope my grid voltage stays above zero though πŸ˜†

davidrapan commented 1 month ago

I do hope my grid voltage stays above zero though πŸ˜†

πŸ˜† πŸ˜† πŸ˜† A good one.

davidrapan commented 1 month ago

I have this strong feeling that we will mess more things up with this than we solve.. If there is anything to solve in the first place, imo.

CrazyUs3r commented 1 month ago

I have ask chatgpt he say the coordinator need samthing like this. @davidrapan can you look

` class SolarmanDataUpdateCoordinator(DataUpdateCoordinator): def init(self, hass, api): super().init(hass, _LOGGER, name="solarman", update_interval=timedelta(minutes=1)) self.api = api self.last_data = None

async def _async_update_data(self):
    try:
        data = await self.api.get_data()
        if data:
            self.last_data = data
        return self.last_data
    except Exception as err:
        _LOGGER.warning("Error fetching data: %s", err)
        return self.last_data

`

gedger commented 1 month ago

I'm sorry but this makes no sense to me as you'll be reporting incorrect values! When the inverter is not connected then the integration has no idea what the true value is so it should be displayed as unavailable. If you display the last value then you will have to check that the inverter is connected to determine whether the sensor value being shown is actually correct which is surely is the wrong way round?

gedger commented 1 month ago

You can use a template sensor to achieve this.

https://community.home-assistant.io/t/support-retrieving-the-last-known-value-in-templates-for-unavailable-sensor-entities/663710

gedger commented 1 month ago

Thinking about this it sounds like you should be trying to work out why the inverter is off-line so much. When I had an issue with a device I setup a command line sensor to regularly run nmap to determine the state of the device. You need to change the IP address to match your inverter.

You get 3 states returned.

3 - Inverter is up and port 8899 is open 2 - Inverter is up but port 8899 is not open 1 - Host not available

command_line:
  - sensor:
      name: Inverter Network Status
      command: "nmap -p 8899 192.168.1.40 | grep -cE 'Starting|8899/tcp open|Host is up'"
      scan_interval: 60   # every 60 seconds
      value_template: "{{ value }}"
mhoogenbosch commented 3 weeks ago

I too have this request. And while I do understand everything above I think it makes sense for a few sensors to keep the value. For example

The inverter total prodcution: image

there is a gap when the inverter is offline, which is understandable but the value goes to unavaiable which is a weird view on a dashboard.

for the total production and daily production I therefor have created the following:

- trigger:
    - platform: state
      entity_id: sensor.inverter_today_production
      not_to:
        - unknown
        - unavailable
  sensor:
    name: "SofarSolar_vandaag_zero"
    state: '{{ trigger.to_state.state }}'
    unique_id: "SofarSolar_vandaag_zero"
    unit_of_measurement: "kWh"
    state_class: "total"
    device_class: "Energy"

- trigger:
    - platform: state
      entity_id: sensor.inverter_total_production
      not_to:
        - unknown
        - unavailable
  sensor:
    name: "SofarSolar_totaal_zero"
    state: '{{ trigger.to_state.state }}'
    unique_id: "SofarSolar_totaal_zero"
    unit_of_measurement: "kWh"
    state_class: "total_increasing"
    device_class: "Energy"

for the current active output I've created the following:

  - name: "SofarSolar_actueel_zero"
    state: "{{ states('sensor.inverter_output_active_power')|float(0) }}"
    unique_id: "SofarSolar_actueel_zero"
    unit_of_measurement: "W"
    state_class: "total"
    device_class: "Energy"

These are all in the template.yaml file and are only used for displaying on a dashboard, to make sure there is just a 0 instead of "unavailable".

davidrapan commented 3 weeks ago

Maybe we could show unavailable only for measurement values...

But still it has so many POV not just that, "Yeah the value proly did not change during that offline period." But what if the inverer just got disconnected from the network? That means it will show again wrong value... But (another one) total wouldn't be that much wrong as measurement values, though...

And many more... lol.

szyx22 commented 2 weeks ago

There is entity "Inverter Device State" so we can see state normal/standby. And we dont want to see this one info in all other 40 entities. For example why after sunshine "today production" is not available if today production is 10kwh etc.