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

Presence of IKEA STYRBAR remote crashes MQTT device discovery #1063

Open
jamesremuscat opened this issue Jan 2, 2025 · 1 comment
Open

Comments

@jamesremuscat
Copy link
Contributor

jamesremuscat commented Jan 2, 2025

Issue does not already exist?

I have searched and found no existing issue

Select Environment

Docker

Home Assistant related?

No

Description

When there is one or more IKEA STYRBAR remote connected to a Zigbee network via zigbee2mqtt, diyhue's MQTT device discovery crashes with a (mostly disguised) error and terminates prematurely.

These devices have a model_id of Remote Control N2. There is a (partial) keymap for this device defined in https://github.com/diyhue/diyHue/blob/master/BridgeEmulator/services/mqtt.py#L122. Because of this, MQTT discovery attempts to look up the model_id in sensorTypes (https://github.com/diyhue/diyHue/blob/master/BridgeEmulator/services/mqtt.py#L313). There is no Remote Control N2 entry in sensorTypes , so a KeyError is raised, and caught here - unhelpfully the only error that is logged is:

2025-01-02 18:37:30,500 - services.mqtt - 411 - INFO - MQTT Exception | 'Remote Control N2'

The first thing I tried was giving this model an entry in sensorTypes, copying from one of the other IKEA entries; while this did prevent the exception and allow MQTT discovery to complete, it wasn't sufficient to have the device work correctly.

One issue is that the device does not send button release events, except for release-after-long-press. This means that diyhue interprets a short press of "on" or "off" as a never-ending long press (until another button is pressed), as the shortcut to evaluating the state-change message returns early if action is null or empty.

At this point I decided that raising an issue here might be worthwhile, in case someone more familiar with the MQTT code would be able to fix things more quickly than I can stumble through it ;)

Errorlog:

diyhue-1  | 2025-01-02 18:37:29,995 - configManager.argumentHandler - 119 - INFO - Using Host 172.21.0.2:80
diyhue-1  | 2025-01-02 18:37:29,995 - configManager.argumentHandler - 120 - INFO - Using Host 172.21.0.2:443
diyhue-1  | 2025-01-02 18:37:29,998 - configManager.argumentHandler - 145 - INFO - Host MAC given as xxxx
diyhue-1  | 2025-01-02 18:37:29,999 - configManager.argumentHandler - 119 - INFO - Using Host 172.21.0.2:80
diyhue-1  | 2025-01-02 18:37:29,999 - configManager.argumentHandler - 120 - INFO - Using Host 172.21.0.2:443
diyhue-1  | 2025-01-02 18:37:30,003 - configManager.argumentHandler - 145 - INFO - Host MAC given as xxxx
diyhue-1  | 2025-01-02 18:37:30,006 - configManager.argumentHandler - 29 - INFO - Debug logging disabled!
diyhue-1  | 2025-01-02 18:37:30,052 - configManager.configHandler - 267 - INFO - Config loaded
diyhue-1  | 2025-01-02 18:37:30,201 - services.updateManager - 30 - INFO - no swversion number update from Philips
diyhue-1  | 2025-01-02 18:37:30,477 - services.updateManager - 66 - INFO - no update for diyHue or UI on github
diyhue-1  | 2025-01-02 18:37:30,478 - services.mqtt - 451 - INFO - Strting MQTT service...
diyhue-1  | 2025-01-02 18:37:30,479 - services.remoteDiscover - 10 - INFO - Starting discovery service
diyhue-1  | 2025-01-02 18:37:30,482 - services.stateFetch - 12 - INFO - start lights sync
diyhue-1  | 2025-01-02 18:37:30,483 - services.ssdp - 25 - INFO - starting ssdp...
diyhue-1  | 2025-01-02 18:37:30,485 - services.ssdp - 39 - INFO - start ssdp broadcast
diyhue-1  | 2025-01-02 18:37:30,486 - services.mdns - 8 - INFO - <MDNS> listener started
diyhue-1  | 2025-01-02 18:37:30,487 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x0017880100d91089/light/config
diyhue-1  | 2025-01-02 18:37:30,489 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x00178801043ee580/light/config
diyhue-1  | 2025-01-02 18:37:30,491 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x001788010486c689/light/config
diyhue-1  |  * Serving Flask app 'HueEmulator3' (lazy loading)
diyhue-1  |  * Environment: production
diyhue-1  |    WARNING: This is a development server. Do not use it in a production deployment.
diyhue-1  |    Use a production WSGI server instead.
diyhue-1  |  * Debug mode: off
diyhue-1  | 2025-01-02 18:37:30,494 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x001788010c00a56f/light/config
diyhue-1  | 2025-01-02 18:37:30,495 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x001788010c00b0ea/light/config
diyhue-1  |  * Serving Flask app 'HueEmulator3' (lazy loading)
diyhue-1  | 2025-01-02 18:37:30,496 - werkzeug - 225 - WARNING -  * Running on all addresses.
diyhue-1  |    WARNING: This is a development server. Do not use it in a production deployment.
diyhue-1  |  * Environment: production
diyhue-1  |    WARNING: This is a development server. Do not use it in a production deployment.
diyhue-1  |    Use a production WSGI server instead.
diyhue-1  |  * Debug mode: off
diyhue-1  | 2025-01-02 18:37:30,496 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x001788010491db83/light/config
diyhue-1  | 2025-01-02 18:37:30,496 - werkzeug - 225 - WARNING -  * Running on all addresses.
diyhue-1  |    WARNING: This is a development server. Do not use it in a production deployment.
diyhue-1  | 2025-01-02 18:37:30,496 - werkzeug - 225 - INFO -  * Running on http://172.21.0.2:80/ (Press CTRL+C to quit)
diyhue-1  | 2025-01-02 18:37:30,497 - werkzeug - 225 - INFO -  * Running on https://172.21.0.2:443/ (Press CTRL+C to quit)
diyhue-1  | 2025-01-02 18:37:30,497 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/1221051039810110150109113116116_1/light/config
diyhue-1  | 2025-01-02 18:37:30,497 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/1221051039810110150109113116116_2/light/config
diyhue-1  | 2025-01-02 18:37:30,497 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/1221051039810110150109113116116_3/light/config
diyhue-1  | 2025-01-02 18:37:30,497 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/1221051039810110150109113116116_4/light/config
diyhue-1  | 2025-01-02 18:37:30,497 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x0017880108ef9495/light/config
diyhue-1  | 2025-01-02 18:37:30,497 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x001788010c0f3a60/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x30fb10fffed9b9fd/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x30fb10fffed8c69f/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x60b647fffe202b45/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/1221051039810110150109113116116_5/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/1221051039810110150109113116116_6/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0xa4c13886fbf077a2/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0xa4c138148f5c326b/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/1221051039810110150109113116116_7/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0xa4c138a7f20dc5a2/light/config
diyhue-1  | 2025-01-02 18:37:30,498 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/1221051039810110150109113116116_8/light/config
diyhue-1  | 2025-01-02 18:37:30,499 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x001788010c2cc5bb/light/config
diyhue-1  | 2025-01-02 18:37:30,499 - services.mqtt - 251 - INFO - Auto discovery message on: homeassistant/light/0x00178801102c46cc/light/config
diyhue-1  | 2025-01-02 18:37:30,500 - services.mqtt - 314 - INFO - MQTT: Add new mqtt sensor Study controller
diyhue-1  | 2025-01-02 18:37:30,500 - services.mqtt - 417 - INFO - MQTT Exception | 'Remote Control N2'

Steps to reproduce

Start diyhue with MQTT discovery enabled, a zigbee2mqtt instance on the same MQTT broker, and a STYRBAR remote on the Zigbee network that doesn't already exist in diyhue's sensors.yaml.

Please enter your operating system details here

Hue-Emulator Version: 2025-01-02 17:21:42.740778641 +0000 (more usefully, built from jamesremuscat@7afd8bb )
WebUI Version: 2024-12-01 10:25:10.000000000 +0000
Architecture: x86_64
OS: Linux
Linux version: #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024
Linux release: 6.8.0-45-generic
Hardware: N/A / Docker

Upload debug tar

DiyHue > Bridge > Bridge Control > Download debug > Full debug fails and raises several exceptions in the log. Let me know what if anything you need.

What DiyHue version(branch) are you using?

master (latest)

@hendriksen-mark
Copy link
Member

hendriksen-mark commented Jan 2, 2025

Hi,
Thank you fro the detailed information.
If i understand correctly with the edit of sensor_types you can add the sensors without diyhue crashing?
For the problem with the remote not doing what you want, most of the mqtt standardSensors are community added.
This means that it is not made by the dev team and there for not tested, to test this you need the actual device.
The person who made this wanted the buttons to do what they do now.
But you can change this, i suggest you change these lines to:

"Remote Control N2": {
        "dataConversion": {
            "rootKey": "action",
            "on": {"buttonevent": 1000},
            "off": {"buttonevent": 4000},
            "brightness_move_up": {"buttonevent": 1001},#hold on
            "brightness_move_down": {"buttonevent": 4001},#hold off
            "brightness_stop": {"buttonevent": 1003},#release on/off
            "arrow_left_click": {"buttonevent": 2000},
            "arrow_left_hold": {"buttonevent": 2001},
            "arrow_left_release": {"buttonevent": 2003},
            "arrow_right_click": {"buttonevent": 3000},
            "arrow_right_hold": {"buttonevent": 3001},
            "arrow_right_release": {"buttonevent": 3003},
        }
    },

If you want the buttons to do something else take a look at this chard to understand what the numbers do:

Button Action Dimmer Button
1000 INITIAL_PRESS Button 1 (ON)
1001 HOLD Button 1 (ON)
1002 SHORT_RELEASED Button 1 (ON)
1003 LONG_RELEASED Button 1 (ON)
2000 INITIAL_PRESS Button 2 (DIM UP)
2001 HOLD Button 2 (DIM UP)
2002 SHORT_RELEASED Button 2 (DIM UP)
2003 LONG_RELEASED Button 2 (DIM UP)
3000 INITIAL_PRESS Button 3 (DIM DOWN)
3001 HOLD Button 3 (DIM DOWN)
3002 SHORT_RELEASED Button 3 (DIM DOWN)
3003 LONG_RELEASED Button 3 (DIM DOWN)
4000 INITIAL_PRESS Button 4 (OFF)
4001 HOLD Button 4 (OFF)
4002 SHORT_RELEASED Button 4 (OFF)
4003 LONG_RELEASED Button 4 (OFF)

The buttons simulate this switch.

Also MQTT is currently under development, take al look at the dev branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants