jason0x43 / hacs-hubitat

A Hubitat integration for Home Assistant
MIT License
191 stars 46 forks source link

Error when creating an automation for an event-emitting device #179

Closed HotshotGT closed 1 year ago

HotshotGT commented 1 year ago

I'm attempting to create a basic automation that turns on a light when my Aqara button is pressed, but I'm running into an error when I try to save it:

Message malformed: Integration " not found

The actual error in the system log:

Logger: homeassistant.components.websocket_api.http.connection
Source: custom_components/hubitat/device_trigger.py:247
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 6:56:00 AM (1 occurrences)
Last logged: 6:56:00 AM

[139866966671568] Error handling message: Unknown error (unknown_error)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/device_automation/__init__.py", line 325, in with_error_handling
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/device_automation/__init__.py", line 390, in websocket_device_automation_list_triggers
    await async_get_device_automations(
  File "/usr/src/homeassistant/homeassistant/components/device_automation/__init__.py", line 250, in async_get_device_automations
    for domain_results in await asyncio.gather(
  File "/usr/src/homeassistant/homeassistant/components/device_automation/__init__.py", line 209, in _async_get_device_automations_from_domain
    return await asyncio.gather(  # type: ignore[no-any-return]
  File "/config/custom_components/hubitat/device_trigger.py", line 122, in async_get_triggers
    trigger_subtypes = get_trigger_subtypes(device, trigger_type)
  File "/config/custom_components/hubitat/device_trigger.py", line 247, in get_trigger_subtypes
    num_buttons = int(device.attributes[ATTR_NUM_BUTTONS].value)
TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

The "pushed" event looks like it's making it to the event server when I press the button:

2022-08-14 06:56:45.894 DEBUG (MainThread) [hubitatmaker.hub] Received event: {'name': 'pushed', 'value': '1', 'displayName': 'Button', 'deviceId': '65', 'descriptionText': None, 'unit': None, 'type': None, 'data': None}
2022-08-14 06:56:45.894 DEBUG (MainThread) [hubitatmaker.hub] Updating pushed of 65 to 1
2022-08-14 06:56:45.896 DEBUG (MainThread) [custom_components.hubitat.hub] Emitted event {'device_id': '65', 'device_name': 'Button', 'attribute': 'pushed', 'value': '1', 'description': None, 'type': None, 'hub': '52bd550c', 'ha_device_id': 'ccc98453526e3928be21c9d94ee9c3ba3d523e146d01c22f78e4799e62c6c1ab::65'}

I'm using the "device" trigger type per the documentation, but I'm not sure if I'm doing something wrong or if there's something else I need to configure. My other Zigbee devices connected to the Hubitat seem to work just fine in automations.

jason0x43 commented 1 year ago

On the Hubitat side, does the driver have a setting for the number of buttons? If so, does it have a value?

Screen Shot 2022-08-16 at 8 22 07 AM

From the error, it looks like the device is returning null for its number of buttons.

HotshotGT commented 1 year ago

I don't seem to have a configuration option for that:

image

I'm using the "Xiaomi Aqara Mijia Sensors and Switches" driver available in the package manager. I've noticed that it creates some HA entities for non-functional sensors on this device (humidity, water, pressure, etc), so I wouldn't mind switching if there's another generic/custom driver that will work better.

Edit: I think I just fixed it. The entity "sensor.button_numberofbuttons" that was created when the button was added through the Hubitat integration was disabled by default. I enabled it, reloaded the integration, and now I no longer get the error. The "Trigger" field under the device trigger in the automation was also blank before, but now it's showing different button press types.

jason0x43 commented 1 year ago

Interesting. I would not have expected that to make a difference for device triggers, but it's good that it did. The integration should really be handling that case (unknown number of buttons) a bit more gracefully. 😄

HotshotGT commented 1 year ago

Interesting. I would not have expected that to make a difference for device triggers, but it's good that it did. The integration should really be handling that case (unknown number of buttons) a bit more gracefully. 😄

Eh, no big deal, just took me a while to figure out where it was getting confused since the initial error message was broken, lol. I appreciate all the work you've put into the project so far regardless. :D