Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZHA integration fails to start with PiZigate on RPI3 #75967

Closed
t0mg opened this issue Jul 30, 2022 · 14 comments
Closed

ZHA integration fails to start with PiZigate on RPI3 #75967

t0mg opened this issue Jul 30, 2022 · 14 comments
Assignees

Comments

@t0mg
Copy link

t0mg commented Jul 30, 2022

The problem

Integration fails to start with error "Error setting up entry ttyAMA0, s/n: n/a for zha". I've been using PiZiGate successfully (bt disabled, uart enabled etc) for at least a couple of years without any trouble. I'm not sure when exactly it started failing (although looking at the logs I suspect this is due to python3).

What version of Home Assistant Core has the issue?

2022.7.7

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

zha

Link to integration documentation on our website

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

Diagnostics information

Logger: homeassistant.config_entries
Source: components/zha/core/gateway.py:172
First occurred: 17:36:44 (1 occurrences)
Last logged: 17:36:44

Error setting up entry ttyAMA0, s/n: n/a for zha

See below for the (probably related) message [zigpy_zigate.common] No module named 'RPi'

Example YAML snippet

N/A

Anything in the logs that might be useful for us?

Here's the error log shown from the ZHA integration card:

Logger: homeassistant.config_entries
Source: components/zha/core/gateway.py:172
First occurred: 17:36:44 (1 occurrences)
Last logged: 17:36:44

Error setting up entry ttyAMA0, s/n: n/a for zha
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 353, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/zha/__init__.py", line 102, in async_setup_entry
    await zha_gateway.async_initialize()
  File "/usr/src/homeassistant/homeassistant/components/zha/core/gateway.py", line 172, in async_initialize
    self.application_controller = await app_controller_cls.new(
  File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 102, in new
    await app.startup(auto_form=auto_form)
  File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 62, in startup
    await self.connect()
  File "/usr/local/lib/python3.10/site-packages/zigpy_zigate/zigbee/application.py", line 39, in connect
    await api.set_raw_mode()
  File "/usr/local/lib/python3.10/site-packages/zigpy_zigate/api.py", line 409, in set_raw_mode
    await self.command(CommandId.SET_RAWMODE, data)
  File "/usr/local/lib/python3.10/site-packages/zigpy_zigate/api.py", line 373, in command
    raise NoStatusError()
zigpy_zigate.api.NoStatusError


And looking in the zigpy_zigate.common logs I find the following:
2022-07-30 17:36:40 ERROR (MainThread) [zigpy_zigate.common] Unable to set PiZiGate GPIO, please check configuration
2022-07-30 17:36:40 ERROR (MainThread) [zigpy_zigate.common] No module named 'RPi'

Full log:
2022-07-30 17:36:07 DEBUG (MainThread) [zigpy.appdb] SQLite version for <module 'sqlite3' from '/usr/local/lib/python3.10/sqlite3/__init__.py'>: 3.38.5
2022-07-30 17:36:13 DEBUG (MainThread) [zhaquirks] Loading quirks module zhaquirks.siglis.zigfred
2022-07-30 17:36:35 DEBUG (MainThread) [zigpy.appdb] Current database version is v9
2022-07-30 17:36:36 DEBUG (MainThread) [zigpy.appdb] Loading application state
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0000] Attribute id: 5 value: Dimmer switch w/o neutral
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0005] Attribute id: 4 value: 0
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0000] Attribute id: 4 value: Legrand
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.quirks.registry] Checking quirks for Legrand Dimmer switch w/o neutral (00:04:74:00:00:8b:5a:50)
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.quirks.registry] Considering <class 'zhaquirks.legrand.dimmer.DimmerWithoutNeutralAndBallast'>
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.quirks.registry] Fail because endpoint list mismatch: {1, 242} {1}
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.quirks.registry] Considering <class 'zhaquirks.legrand.dimmer.DimmerWithoutNeutral3'>
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.quirks.registry] Fail because endpoint list mismatch: {1, 242} {1}
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.quirks.registry] Considering <class 'zhaquirks.legrand.dimmer.DimmerWithoutNeutral2'>
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.quirks.registry] Fail because endpoint list mismatch: {1, 242} {1}
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.quirks.registry] Considering <class 'zhaquirks.legrand.dimmer.DimmerWithoutNeutral'>
2022-07-30 17:36:39 DEBUG (MainThread) [zigpy.quirks.registry] Found custom device replacement for 00:04:74:00:00:8b:5a:50: <class 'zhaquirks.legrand.dimmer.DimmerWithoutNeutral'>
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0000] Attribute id: 5 value: Dimmer switch w/o neutral
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0005] Attribute id: 2 value: 0
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0005] Attribute id: 1 value: 0
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0005] Attribute id: 4 value: 0
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0000] Attribute id: 4 value: Legrand
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0000] Attribute id: 2 value: 66
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0000] Attribute id: 16384 value: 0026
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0000] Attribute id: 7 value: 1
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0008] Attribute id: 0 value: 0
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x000f] Attribute id: 85 value: 0
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0006] Attribute id: 0 value: 0
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0008] Attribute id: 17 value: 99
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0006] Attribute id: 16387 value: 255
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy.appdb] [0x5a41:1:0x0008] Attribute id: 16 value: 5
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy_zigate.uart] PiZiGate detected
2022-07-30 17:36:40 ERROR (MainThread) [zigpy_zigate.common] Unable to set PiZiGate GPIO, please check configuration
2022-07-30 17:36:40 ERROR (MainThread) [zigpy_zigate.common] No module named 'RPi'
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy_zigate.uart] Connection made
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy_zigate.api] Sending CommandId.SET_RAWMODE (b'\x01'), waiting for status: True, waiting for response: None
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy_zigate.uart] Send: 0x0002 b'01'
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy_zigate.uart] Frame to send: b'\x00\x02\x00\x01\x02\x01'
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy_zigate.uart] Frame escaped: b'\x02\x10\x02\x12\x02\x10\x02\x11\x02\x12\x02\x11'
2022-07-30 17:36:40 DEBUG (MainThread) [zigpy_zigate.api] Wait for status to command CommandId.SET_RAWMODE
2022-07-30 17:36:41 DEBUG (MainThread) [zigpy_zigate.uart] Send: 0x0002 b'01'
2022-07-30 17:36:41 DEBUG (MainThread) [zigpy_zigate.uart] Frame to send: b'\x00\x02\x00\x01\x02\x01'
2022-07-30 17:36:41 DEBUG (MainThread) [zigpy_zigate.uart] Frame escaped: b'\x02\x10\x02\x12\x02\x10\x02\x11\x02\x12\x02\x11'
2022-07-30 17:36:43 DEBUG (MainThread) [zigpy_zigate.uart] Send: 0x0002 b'01'
2022-07-30 17:36:43 DEBUG (MainThread) [zigpy_zigate.uart] Frame to send: b'\x00\x02\x00\x01\x02\x01'
2022-07-30 17:36:43 DEBUG (MainThread) [zigpy_zigate.uart] Frame escaped: b'\x02\x10\x02\x12\x02\x10\x02\x11\x02\x12\x02\x11'
File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 102, in new
File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 62, in startup
File "/usr/local/lib/python3.10/site-packages/zigpy_zigate/zigbee/application.py", line 39, in connect
File "/usr/local/lib/python3.10/site-packages/zigpy_zigate/api.py", line 409, in set_raw_mode
File "/usr/local/lib/python3.10/site-packages/zigpy_zigate/api.py", line 373, in command
zigpy_zigate.api.NoStatusError

Additional information

No response

@probot-home-assistant
Copy link

zha documentation
zha source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @dmulcahey, @Adminiuga, @puddly, mind taking a look at this issue as it has been labeled with an integration (zha) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@Adminiuga
Copy link
Contributor

Pizigate is only hardware depending GPIO and it is only applicable on RPi.

zigpy-zigate has a platform specific dependency on GPIO, but when HA installs zigpy-zigate, that dependency is not installed.
I know HA deprecated GPIO integrations and I'm not sure how to handle this correctly?

@pvizeli any recommendations?

@puddly
Copy link
Contributor

puddly commented Jul 31, 2022

#75755 (comment) mentioned that adding RPi.GPIO as a dependency of a custom integration fixed the problem. Perhaps there is some issue with the zigpy-zigate is_raspberry_pi code: https://github.com/zigpy/zigpy-zigate/blob/c946c620df55cc8b7fc7982b80f93cfa058b282e/setup.py#L9-L48

@Adminiuga
Copy link
Contributor

/proc/cpuinfo is available inside home assistant core container. Does ha core dependency installer use setup.py for installation though?

@puddly
Copy link
Contributor

puddly commented Jul 31, 2022

It should, it's just running pip install:

def install_package(
package: str,
upgrade: bool = True,
target: str | None = None,
constraints: str | None = None,
find_links: str | None = None,
timeout: int | None = None,
no_cache_dir: bool | None = False,
) -> bool:
"""Install a package on PyPi. Accepts pip compatible package strings.
Return boolean if install successful.
"""
# Not using 'import pip; pip.main([])' because it breaks the logger
_LOGGER.info("Attempting install of %s", package)
env = os.environ.copy()
args = [sys.executable, "-m", "pip", "install", "--quiet", package]
if timeout:
args += ["--timeout", str(timeout)]
if no_cache_dir:
args.append("--no-cache-dir")
if upgrade:
args.append("--upgrade")
if constraints is not None:
args += ["--constraint", constraints]
if find_links is not None:
args += ["--find-links", find_links, "--prefer-binary"]
if target:
assert not is_virtual_env()
# This only works if not running in venv
args += ["--user"]
env["PYTHONUSERBASE"] = os.path.abspath(target)
_LOGGER.debug("Running pip command: args=%s", args)
with Popen(args, stdin=PIPE, stdout=PIPE, stderr=PIPE, env=env) as process:
_, stderr = process.communicate()
if process.returncode != 0:
_LOGGER.error(
"Unable to install package %s: %s",
package,
stderr.decode("utf-8").lstrip().strip(),
)
return False
return True

@pvizeli
Copy link
Member

pvizeli commented Aug 1, 2022

/proc/cpuinfo is available inside home assistant core container. Does ha core dependency installer use setup.py for installation though?

Things like this don't work in a VM/Container. Also, we generate the image on x86 hardware. I said that before on discord, but this setup.py will not work with the build system. There is no solution. The only way that would work is to use the GPIO from the standardized Linux kernel, not the downstream implementation.

@puddly
Copy link
Contributor

puddly commented Aug 1, 2022

Perhaps we can migrate zigpy-zigate to https://github.com/gpiozero/gpiozero? It has no external dependencies and can be installed on non-pi platforms.

@puddly
Copy link
Contributor

puddly commented Aug 7, 2022

@t0mg @jankovac503 try out the latest HA Core release, 2022.8.2.

@t0mg
Copy link
Author

t0mg commented Aug 10, 2022

@puddly thanks for the heads up. Just updated to 2022.8.3 and no luck:

Logger: homeassistant.config_entries
Source: components/zha/core/gateway.py:170
First occurred: 10 août 2022 à 18:37:59 (1 occurrences)
Last logged: 10 août 2022 à 18:37:59

Error setting up entry ttyAMA0, s/n: n/a for zha
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 357, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/usr/src/homeassistant/homeassistant/components/zha/__init__.py", line 112, in async_setup_entry
    await zha_gateway.async_initialize()
  File "/usr/src/homeassistant/homeassistant/components/zha/core/gateway.py", line 170, in async_initialize
    self.application_controller = await app_controller_cls.new(
  File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 118, in new
    await app.startup(auto_form=auto_form)
  File "/usr/local/lib/python3.10/site-packages/zigpy/application.py", line 66, in startup
    await self.connect()
  File "/usr/local/lib/python3.10/site-packages/zigpy_zigate/zigbee/application.py", line 39, in connect
    await api.set_raw_mode()
  File "/usr/local/lib/python3.10/site-packages/zigpy_zigate/api.py", line 409, in set_raw_mode
    await self.command(CommandId.SET_RAWMODE, data)
  File "/usr/local/lib/python3.10/site-packages/zigpy_zigate/api.py", line 373, in command
    raise NoStatusError()
zigpy_zigate.api.NoStatusError

@puddly puddly mentioned this issue Aug 22, 2022
23 tasks
@Hedda
Copy link
Contributor

Hedda commented Aug 25, 2022

@t0mg have you tried the new Home Assistant Core release 2022.8.7 which contains updated zigpy-zigate library?

#77125

Bump ZHA dependencies:

  • zigpy from 0.49.1 to 0.50.2
  • zigpy-zigate from 0.9.1 to 0.9.2
  • zigpy-znp from 0.8.1 to 0.8.2
  • bellows from 0.32.0 to 0.33.1

https://github.com/zigpy/zigpy-zigate/releases/tag/0.9.2

Changes

@dmulcahey
Copy link
Contributor

@Hedda .7 hasn’t been released yet

@puddly
Copy link
Contributor

puddly commented Aug 27, 2022

Confirmed working in duplicate issue #75755

@puddly puddly closed this as completed Aug 27, 2022
@t0mg
Copy link
Author

t0mg commented Aug 27, 2022

Confirmed here on .7 as well! Thanks 🙏

@github-actions github-actions bot locked and limited conversation to collaborators Sep 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants