Hi.
I am trying to send commands to the IC MCP2200 (usb HID), my computer has Hassio and AppDaemon 4, my configuration:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Control IC MCP2200 USB-HID.
import appdaemon.plugins.hass.hassapi as hass
import usb
import usb.core
import usb.util
import usb.backend.libusb1
import sys
import os
#import asyncio
import queue
commands = queue.Queue()
class Context:
dev_usb_hid = None
# -------------------------------------------------------
class UsbRelay (hass.Hass):
def initialize(self):
self.connect_usb_hid()
# -------------------------------------------------------
def connect_usb_hid(self):
connected = False
while not connected:
if Context.dev_usb_hid == None:
self.debug("Ini. USB-HID ... ")
if hasattr(usb, 'version_info'):
self.debug("Version pyusb: " + str (usb.version_info))
backend = usb.backend.libusb1.get_backend()
self.debug('Backend: ' + str (backend))
if backend is None:
self.debug("Error usb-libusb!!")
else:
dev_usb_hid = usb.core.find(idVendor=0x04d8, idProduct=0x00df, backend=backend)
if dev_usb_hid is None:
self.debug("No MCP2200!!")
connected = False
else:
self.debug("OK MCP2200")
connected = True
for dev in dev_usb_hid:
serial_num = usb.util.get_string(dev,dev.iSerialNumber)
if dev.is_kernel_driver_active(2):
dev.detach_kernel_driver(2)
usb.util.claim_interface(dev, 2)
HID_INTERFACE = self.args["MCP2200_HID_INTERFACE"]
endpoint = dev_usb_hid[0][(HID_INTERFACE,0)][1]
self.debug('Endpoint: \n' + str (endpoint))
inipoint = dev_usb_hid[0][(HID_INTERFACE,0)][0]
self.debug('Inipoint: \n' + str (inipoint))
get_status_cmd = [0x80] + [0]*15
cfg_cmd = [0x10] + [0]*15
cfg_cmd[6] = 0xc3 #defecto GPIOS bitmap->11000011
cfg_cmd[9] =0x67 # 115200bps ->103
dev.write(endpoint.bEndpointAddress, get_status_cmd)
self.debug('RX Config. NVRAM: ' + str (resp))
continue
if not connected:
asyncio.sleep(2)
# ----------------------------------------------------
def terminate(self):
if Context.dev_usb_hid != None:
Context.dev_usb_hid.close()
# ----------------------------------------------------
def debug(self, text):
if self.args["DEBUG"] == 1:
self.log('DEBUG: ' + text)
I obtain this result:
2022-10-09 12:37:50.095833 INFO usb-hdi_relay: DEBUG: Ini. USB-HID ...
2022-10-09 12:37:50.098047 INFO usb-hdi_relay: DEBUG: Version pyusb: (1, 2, 1)
2022-10-09 12:37:50.117884 INFO usb-hdi_relay: DEBUG: Backend: <usb.backend.libusb1._LibUSB object at 0x7fb1b2008f70>
2022-10-09 12:37:50.121085 INFO usb-hdi_relay: DEBUG: OK MCP2200
2022-10-09 12:37:50.123755 WARNING usb-hdi_relay: ------------------------------------------------------------
2022-10-09 12:37:50.124689 WARNING usb-hdi_relay: Unexpected error running initialize() for usb-hdi_relay
2022-10-09 12:37:50.125243 WARNING usb-hdi_relay: ------------------------------------------------------------
2022-10-09 12:37:50.127767 WARNING usb-hdi_relay: Traceback (most recent call last):
File "/usr/lib/python3.10/site-packages/appdaemon/app_management.py", line 165, in initialize_app
await utils.run_in_executor(self, init)
File "/usr/lib/python3.10/site-packages/appdaemon/utils.py", line 337, in run_in_executor
response = future.result()
File "/usr/lib/python3.10/concurrent/futures/thread.py", line 58, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/appdaemon/apps/usb_relay_1.py", line 30, in initialize
self.connect_usb_hid()
File "/config/appdaemon/apps/usb_relay_1.py", line 89, in connect_usb_hid
serial_num = usb.util.get_string(dev_usb_hid,3)
File "/usr/lib/python3.10/site-packages/usb/util.py", line 313, in get_string
raise ValueError("The device has no langid"
ValueError: The device has no langid (permission issue, no string descriptors supported or device error)
2022-10-09 12:37:50.130290 WARNING usb-hdi_relay: -----------------------------------------------------------
but that doesnt matter at all, because when it would go right, AD would never start, because you cant use a while loop in an initialise.
AD would never be able to finish starting after that loop starts running.
i think you can better find help on the HA discord.
HI, the problem i think is a permissions problem, if i check the obtained in:
dev_usb_hid = usb.core.find(idVendor=0x04d8, idProduct=0x00df, backend=backend)
I created a file with this rule:ATTRS{idVendor}==â04d8â, ATTRS{idProduct}==â00dfâ, GROUP:=âdaemonâ, MODE=â0660â (pendrive-USB->CONFIG/udev/50-mcp2200.rules), but it does not solve the problem. Thanks
Just started using Appdaemon plugin couple of quick questions (using HA OS)
a) does it try to download Python dependencies after each restart (or maybe thatâs just what it looks like in the logs)
b) is there a log path if I wanted to tail the after an Appdaemon restart? Rather than using the web tab
c) if thereâs a Python package it doesnât find (that Iâve used elsewhere in the past) is there a way to load this? Or should I look for another similar Python package that can be found? Eg xml.etree.ElementTree
Hi all.
Someone noticed that doing a âreload templateâ (service Template entities) from home assistant, in appDaemon the template entities (sensor, select etc) return none for 5-6 minutes (as if they were frozen)
Restarting the addon returns everything to normal until the Template entities service is run again.
Anyone have any idea why my python scripts can no longer detect dependencies installed by AppDaemon? This used to work, but now it doesnât. I tried rolling back AppDaemon to v0.7.x, but the result is the same so maybe something changed in how the HA system python interacts with AppDaemon? Where does AppDaemon install python packages to?
Version 0.14.0 has a breaking change: âDrop support for armhf & i386â.
This has a scary ring to it: Two of my HA instances are running on PCs (one Intel NUC with an i5 processor running HA Supervised, and one old laptop with an i7 processor running HA OS).
Does the âdrop supportâ mean what it sounds like: That I shouldnât upgrade to 0.14.0 on these two instances. (I noticed the same for the Z-Wave JS UI upgrade and for the Node-Red upgrade.)
I see this message when I start appdaemon after update to 0.15.2
[07:07:06] INFO: Starting AppDaemon...
s6-rc: info: service legacy-services successfully started
Traceback (most recent call last):
File "/usr/bin/appdaemon", line 8, in <module>
ERROR Error loading secrets file: /config/secrets.yaml
sys.exit(main())
^^^^^^
File "/usr/lib/python3.11/site-packages/appdaemon/__main__.py", line 417, in main
admain.main()
File "/usr/lib/python3.11/site-packages/appdaemon/__main__.py", line 276, in main
if "appdaemon" not in config:
^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: argument of type 'NoneType' is not iterable
[07:07:09] INFO: Service AppDaemon exited with code 1 (by signal 0)
EDIT :
Turns out this WAS a stupid question, as the package in question has nothing to do with AppDaemon but was actually in my AppDaemon config as a âSystem packageâ for⌠reasons that probably make sense to the me of over a year ago but are lost to the sands of time. So totally my fault, leaving this up merely to shame myself.
I feel like this is going to be a stupid question but : anyone ever gotten this message? I updated to 0.16.0 this morning and AppDaemon wonât start, the log seems to say that iâts having trouble finding the chromium-chromedriver package. I assume that all happens under the covers so not sure what I should do to fix it. Running HA-OS on a RPi 4b.
Executing fontconfig-2.14.2-r4.trigger
OK: 121 MiB in 104 packages
ERROR: unable to select packages:
chromium-chromedriver (no such package):
required by: world[chromium-chromedriver]
[16:14:22] FATAL: Failed installing package chromium-chromedriver
s6-rc: warning: unable to start service init-appdaemon: command exited 1
/run/s6/basedir/scripts/rc.init: warning: s6-rc failed to properly bring all the services up! Check your logs (in /run/uncaught-logs/current if you have in-container logging) for more information.
/run/s6/basedir/scripts/rc.init: fatal: stopping the container.
s6-rc: info: service legacy-cont-init: stopping