home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.15k stars 30.19k forks source link

After starting system the OpenTherm Gateway integration fails to set up #101837

Closed Caius-Bonus closed 6 months ago

Caius-Bonus commented 12 months ago

The problem

When starting the system (with "Reboot system" in HomeAssistant OS or just plugging in the power), the OpenTherm Gateway integration will always have "Failed to set up". This does never occur when only restarting Home Assistant using "Restart Home Assistant" in HomeAssistant OS. An error is always logged in the Logs about the reason.

Manual or Automated (using an Automation) reloading of the integration after a certain amount of time always resolves the issue.

What version of Home Assistant Core has the issue?

core-2023.10.1

What was the last working version of Home Assistant Core?

unknown

What type of installation are you running?

Home Assistant OS

Integration causing the issue

OpenTherm Gateway

Link to integration documentation on our website

https://www.home-assistant.io/integrations/opentherm_gw/

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: homeassistant.config_entries
Source: config_entries.py:399

Error setting up entry OpenTherm Gateway for opentherm_gw
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 399, in async_setup
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/opentherm_gw/__init__.py", line 116, in async_setup_entry
    await gateway.connect_and_subscribe()
  File "/usr/src/homeassistant/homeassistant/components/opentherm_gw/__init__.py", line 413, in connect_and_subscribe
    self.status = await self.gateway.connect(self.device_path)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyotgw/pyotgw.py", line 53, in connect
    if not await self.connection.connect(port, timeout):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyotgw/connection.py", line 59, in connect
    transport, protocol = await self._connecting_task
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyotgw/connection.py", line 126, in _attempt_connect
    await asyncio.wait_for(
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 479, in wait_for
    return fut.result()
           ^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyotgw/protocol.py", line 134, in init_and_wait_for_activity
    await self.command_processor.issue_cmd(v.OTGW_CMD_SUMMARY, 0, retry=0)
  File "/usr/local/lib/python3.11/site-packages/pyotgw/commandprocessor.py", line 92, in issue_cmd
    ret = await process(msg)
          ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/pyotgw/commandprocessor.py", line 57, in process
    raise v.OTGW_ERRS[msg]
SyntaxError: Syntax Error: The command contained an unexpected character or was incomplete.

Additional information

I don't know if the following is relevant, but: I run on a Raspberry Pi 3B with the official power supply (I see no power issues in the history of the systemmonitor integration) and have multiple other integrations running, but no Addons. I use the OpenTherm Gateway Kit from NodoShop over USB and have no Thermostat attached, but only a Boiler (this is because I have different thermostats in different rooms and these are not OpenTherm capable). OpenTherm Gateway Firmware: 5.8 OpenTherm Gateway Microcontroller: P16F88

This happens after "Restart Home Assistant" (which causes no issues, but sounds relevant): Logger: homeassistant.config_entries Source: config_entries.py:441 Config entry 'OpenTherm Gateway' for opentherm_gw integration not ready yet: Could not connect to gateway at: ; Retrying in background

Logger: pyotgw.pyotgw Source: components/opentherm_gw/init.py:408 Timed out waiting for command: MM, value: -.

home-assistant[bot] commented 12 months ago

Hey there @mvn23, mind taking a look at this issue as it has been labeled with an integration (opentherm_gw) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `opentherm_gw` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign opentherm_gw` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


opentherm_gw documentation opentherm_gw source (message by IssueLinks)

mvn23 commented 11 months ago

Can you enable debugging for the library by adding the following to configuration.yaml and provide the logs?

logger:
  default: warning
  logs:
    pyotgw.*: debug
Caius-Bonus commented 11 months ago

Sure. Thanks for the quick response. The configuration didn't work for some reason, but I got it working by clicking "Enable debug logging" in the gui. Hereby the full log. 5minutes after boot it will run an automation that reloads the integration. I stopped it after the first report. pyotgw until first report.log

mvn23 commented 11 months ago

Thank you for the log. Can you also upload debug logs of the last moments before Home Assistant restarts? You indicated that there are also some log entries when using Restart Home Assistant when the issue does not occur. This may indeed be relevant, so if you can provide logs of both scenarios that would be great.

Caius-Bonus commented 11 months ago

Thanks for the quick response again. I was able to easily get the soft restart ("Restart Home Assistant") log here until the first report. pyotgw soft restart.log.

The log from before shutdown seemed a little more difficult to get from a raspberry pi with "Home Assistant OS" (I would have to shutdown cleanly and eject the SD card from what I could find), so I could try when I have a little more time if necessary. However the behaviour is the same during an unplug and replug and a hard restart ("Reboot system"), so I don't know how useful it would be.

Edit: it's just in /config.

Caius-Bonus commented 11 months ago

I have a log here for a soft restart ("Restart Home Assistant") until hard restart ("Reboot system"). I took it from /config/home-assistant.log.1.

pyotgw before shutdown.txt

mvn23 commented 11 months ago

Thank you for the logs. It looks like there's some leftover data on the serial line after a reboot and I just wanted to make sure we're not causing that during shutdown (the SyntaxError is actually reported by the gateway, we just raise it in pyotgw) I spotted some changes I can make to pyotgw to make things a bit more robust. Unfortunately I just moved house and haven't connected my OpenTherm Gateway yet, so the fix may take a while to appear.

As for the log entry when using Restart Home Assistant, this may actually be a result of reconnecting too quickly after disconnecting. I'll need to do some more testing to confirm that though.

Caius-Bonus commented 11 months ago

Thanks, I'll test it when it arrives.

MedicoreV8 commented 10 months ago

It seems that I have the same annoying error. My NUC reboots after a power outage and automatically restarts VMware player and Home assistant with all USB Devices automatically connected. However, the OTGW integration is the only one that won't automatically start back up. Hope this will be fixed soon :)

digital-IMEI commented 10 months ago

Same issue here since several weeks.

KJagersma commented 9 months ago

Maybe it's related to a similar issue I'm having: I have an older otgw which I was trying to use again and I was getting a consistent SE response on the first OTGW_CMD_SUMMARY command, so my integration setup was never successful. I made a custom component copy of this integration, including the pyotgw lib, and changed the retry param in init_and_wait_for_activity to 3, which seems to do the trick. I assumed there was a special reason to use a retry count of zero here, but this results in an instant connect exception with my setup. I'm running old firmware on nodo-shop hardware ((PR=A:OpenTherm Gateway 4.2.4 / hardware v2.0)

MedicoreV8 commented 9 months ago

Maybe it's related to a similar issue I'm having: I have an older otgw which I was trying to use again and I was getting a consistent SE response on the first OTGW_CMD_SUMMARY command, so my integration setup was never successful. I made a custom component copy of this integration, including the pyotgw lib, and changed the retry param in init_and_wait_for_activity to 3, which seems to do the trick. I assumed there was a special reason to use a retry count of zero here, but this results in an instant connect exception with my setup. I'm running old firmware on nodo-shop hardware ((PR=A:OpenTherm Gateway 4.2.4 / hardware v2.0)

I also have an old OTGW, black rectangular box, no ethernet. I did update to the latest firmware. If I knew what to order I would have ordered a new one. I also have no clue how to do the aforementioned steps :(

digital-IMEI commented 9 months ago

Thanks for sharing! Is this something that could be changed via the interface as well? Or only in the code?It’s the protocol.py file you updated, right? Ivo Op 13 dec 2023 om 23:05 heeft KJagersma @.***> het volgende geschreven: Maybe it's related to a similar issue I'm having: I have an older otgw which I was trying to use again and I was getting a consistent SE response on the first OTGW_CMD_SUMMARY command, so my integration setup was never successful. I made a custom component copy of this integration, including the pyotgw lib, and changed the retry param in init_and_wait_for_activity to 3, which seems to do the trick. I assumed there was a special reason to use a retry count of zero here, but this results in an instant connect exception with my setup. I'm running old firmware on nodo-shop hardware ((PR=A:OpenTherm Gateway 4.2.4 / hardware v2.0)

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: @.***>

KJagersma commented 9 months ago

Thanks for sharing! Is this something that could be changed via the interface as well? Or only in the code?It’s the protocol.py file you updated, right?

If you have the vscode plugin, and know what you are doing with python, you could update this code trough the interface. I have also posted this issue in the pyotgw module, if this is a bug, this would be the place to fix this. I'm not sure about the update flow of used python modules in ha, so hopefully @mvn23 will comment about what to do next, or if there is a workaround possible.

KJagersma commented 9 months ago

Sorry for polluting this issue with my remarks. Although the logged integration error was the same, my problem was a configuration error in my espeasy wifi module (serial log level).

MedicoreV8 commented 9 months ago

Thanks for sharing! Is this something that could be changed via the interface as well? Or only in the code?It’s the protocol.py file you updated, right?

If you have the vscode plugin, and know what you are doing with python, you could update this code trough the interface. I have also posted this issue in the pyotgw module, if this is a bug, this would be the place to fix this. I'm not sure about the update flow of used python modules in ha, so hopefully @mvn23 will comment about what to do next, or if there is a workaround possible.

How? I can't find where this integration is installed. I only have the custom_components folder but (obviously) it's not there.

KJagersma commented 9 months ago

If you have the vscode plugin, and know what you are doing with python, you could update this code trough the interface. I have also posted this issue in the pyotgw module, if this is a bug, this would be the place to fix this. I'm not sure about the update flow of used python modules in ha, so hopefully @mvn23 will comment about what to do next, or if there is a workaround possible.

How? I can't find where this integration is installed. I only have the custom_components folder but (obviously) it's not there.

I'm not sure with which part you are asking help, so I'll just describe the steps I've taken to get get this in an editable state. Disclaimer: I don't have experience with python or ha custom integrations, so there is probably a better way to do this.

The vscode HA add-on is just used for editing and uploading files, so not really important. First step is to run a custom version of the integration, so copy the opentherm_gw directory to the config/custom_components directory. Add a version item to the manifest.json file, value doesn't really matter I think. After restart you should see a message on the opentherm integration page about running as a custom integration.

If this is running, you can now add a custom version of the pyotgw module for testing. Copy the pyotgw directory as a subdirectory of your custom integration. To actually use this, you need to add the path of the integration so the module can be found, I've done this by adding:

import os
import sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

just before the import pyotgw call in the file __init__.py (The one in the opentherm_gw dir) Warning: since this is the only usage of this module, it's probably ok to do it like this, but in general I assume it's bad advice to do it this way, since path is global, which could mess up your installation if you are using this to debug modules which are shared.

To enable logging, just click enable debug logging on the integration page, this also enables logging for the pyotgw module.

issue-triage-workflows[bot] commented 6 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.