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

[NEW DEVICE] ZNXNKG02LM #430

Closed
snalty opened this issue Feb 12, 2022 · 19 comments
Closed

[NEW DEVICE] ZNXNKG02LM #430

snalty opened this issue Feb 12, 2022 · 19 comments
Assignees
Labels
new-device New device

Comments

@snalty
Copy link

snalty commented Feb 12, 2022

New Device Support

Device Information

  • Device Model: ZNXNKG02LM
  • Device Description: Aqara knob H1 (wireless)
  • Device Manufacturer: Xiaomi/Aqare

Integrations

Integration: z2m

Actions

  • single: Sent when the knob is pressed
  • double: Sent when the knob is pressed twice
  • hold: Sent when the knob is held.
  • release: Sent when the hold is released.
  • start_rotating: Sent when rotation starts.
  • stop_rotating: Sent when rotation ends

Notes

The rotation events from z2m don't have the rotation direction in the action, here are the mqtt events from a slow quarter turn:

Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"start_rotating","action_rotation_angle":12,"action_rotation_angle_speed":12,"action_rotation_percent":3.3333332538604736,"action_rotation_percent_speed":3.3333332538604736,"action_rotation_time":200,"battery":100,"linkquality":99,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"","action_rotation_angle":null,"action_rotation_angle_speed":null,"action_rotation_percent":null,"action_rotation_percent_speed":null,"action_rotation_time":null,"battery":100,"linkquality":99,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob/action', payload 'start_rotating'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"rotation","action_rotation_angle":60,"action_rotation_angle_speed":48,"action_rotation_percent":16.66666603088379,"action_rotation_percent_speed":13.333333015441895,"action_rotation_time":700,"battery":100,"linkquality":99,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"","action_rotation_angle":null,"action_rotation_angle_speed":null,"action_rotation_percent":null,"action_rotation_percent_speed":null,"action_rotation_time":null,"battery":100,"linkquality":99,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob/action', payload 'rotation'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"stop_rotating","action_rotation_angle":60,"action_rotation_angle_speed":0,"action_rotation_percent":16.66666603088379,"action_rotation_percent_speed":0,"action_rotation_time":700,"battery":100,"linkquality":102,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"","action_rotation_angle":null,"action_rotation_angle_speed":null,"action_rotation_percent":null,"action_rotation_percent_speed":null,"action_rotation_time":null,"battery":100,"linkquality":102,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob/action', payload 'stop_rotating'

and the events from a quick half turn:

Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"start_rotating","action_rotation_angle":132,"action_rotation_angle_speed":132,"action_rotation_percent":36.66666793823242,"action_rotation_percent_speed":36.66666793823242,"action_rotation_time":200,"battery":100,"linkquality":96,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"","action_rotation_angle":null,"action_rotation_angle_speed":null,"action_rotation_percent":null,"action_rotation_percent_speed":null,"action_rotation_time":null,"battery":100,"linkquality":96,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob/action', payload 'start_rotating'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"rotation","action_rotation_angle":156,"action_rotation_angle_speed":24,"action_rotation_percent":43.33333206176758,"action_rotation_percent_speed":6.666666507720947,"action_rotation_time":700,"battery":100,"linkquality":78,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"","action_rotation_angle":null,"action_rotation_angle_speed":null,"action_rotation_percent":null,"action_rotation_percent_speed":null,"action_rotation_time":null,"battery":100,"linkquality":78,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob/action', payload 'rotation'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"stop_rotating","action_rotation_angle":156,"action_rotation_angle_speed":0,"action_rotation_percent":43.33333206176758,"action_rotation_percent_speed":0,"action_rotation_time":700,"battery":100,"linkquality":105,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob', payload '{"action":"","action_rotation_angle":null,"action_rotation_angle_speed":null,"action_rotation_percent":null,"action_rotation_percent_speed":null,"action_rotation_time":null,"battery":100,"linkquality":105,"operation_mode":null,"state":"OFF","temperature":25,"voltage":3079}'
Info MQTT publish: topic 'zigbee2mqtt/smart_knob/action', payload 'stop_rotating'
@snalty snalty added the new-device New device label Feb 12, 2022
xaviml added a commit that referenced this issue Apr 15, 2022
@xaviml
Copy link
Owner

xaviml commented Apr 15, 2022

Hi all,

I released ControllerX v4.19.0b1 with this new controller added. If not problems are raised, I will release v4.19.0.

Regards,
Xavi M.

@bartplessers
Copy link

@snalty , where did you buy this device? I'm very interested in this remote, but can't find a webshop where it's available...

@snalty
Copy link
Author

snalty commented Apr 21, 2022

I bought it from AliExpress but it seems it was either discontinued or is very hard to find.

Also, brightness control isn't working with this latest beta but I've not yet had chance to look into it. Will post my findings on the release.

@xaviml
Copy link
Owner

xaviml commented Apr 21, 2022

Hi @snalty ,

You can share in here your findings. Either point me on what is not working, or share the logs with me to check them out.

Regards,
Xavi M.

@snalty
Copy link
Author

snalty commented Apr 21, 2022

Hi @xaviml
Here are some quick logs from appdaemon:

022-04-21 19:29:19.546036 INFO bedroom_light: 🎮 Button event triggered: start_rotating

2022-04-21 19:29:19.548261 INFO bedroom_light: 🏃 Running Predefined (brightness_from_controller_angle) now
2022-04-21 19:29:19.551307 WARNING bedroom_light: No event data present
2022-04-21 19:29:20.297191 INFO bedroom_light: 🎮 Button event triggered: stop_rotating
2022-04-21 19:29:20.299606 INFO bedroom_light: 🏃 Running Predefined (release) now

I imagine the line saying there was no event data is of interest.

Will provide more info later

@xaviml
Copy link
Owner

xaviml commented Apr 21, 2022

Hi @snalty ,

Sorry, I did not mention it to you, but I placed it in the documentation. You need to use "listen_to: mqtt" for the zigbee2mqtt integration. Otherwise the brightness change will not work since the action name does not indicate if rotation is left or right, this is only available on the MQTT payload.

Please, read here (zigbee2mqtt and mqtt sections) on how to configure the mqtt listener: https://xaviml.github.io/controllerx/others/integrations

Regards,

@xaviml
Copy link
Owner

xaviml commented Apr 21, 2022

Does the 1 and 2 clicks work as expected (toggle and full brightness respectively)?

@snalty
Copy link
Author

snalty commented Apr 21, 2022

Yeah that works fine, just the brightness stuff

@snalty
Copy link
Author

snalty commented Apr 21, 2022

Brightness control is mostly working great now I have configured mqtt access in appdaemon.yaml. Just a few things I need to look into before I feedback:

  • The color of the light sometimes randomy changes?
  • If it rotate the dial counter clockwise, then immediately clockwise any further forward clockwise rotation will cause the light to continue dimmings as if i was turning the dial counter clockwise.

@snalty
Copy link
Author

snalty commented Apr 21, 2022

Okay so here is an example. I've put print statements underneath line 578 in light_controller.py such that the method brightness_from_controller_angle looks like this:

@action
    async def brightness_from_controller_angle(
        self,
        mode=StepperMode.STOP,
        steps: Optional[Number] = None,
        extra: Optional[EventData] = None,
    ) -> None:
        if extra is None:
            self.log("No event data present", level="WARNING")
            return
        if isinstance(self.integration, Z2MIntegration):
            if "action_rotation_angle" not in extra:
                self.log(
                    "`action_rotation_angle` is not present in the MQTT payload",
                    level="WARNING",
                )
                return
            angle = extra["action_rotation_angle"]
            direction = StepperDir.UP if angle > 0 else StepperDir.DOWN
            print(angle)
            print(direction)
            await self._hold(
                LightController.ATTRIBUTE_BRIGHTNESS, direction, mode=mode, steps=steps
            )

You can see now in the logs below even though the angle is -24 and the direction is down the brightness is increasing. Weird bug!

2022-04-21 23:07:11.524515 INFO bedroom_light: 🎮 Button event triggered: `start_rotating`
2022-04-21 23:07:11.534596 INFO bedroom_light: 🏃 Running `Predefined (brightness_from_controller_angle)` now
12
up
2022-04-21 23:07:11.558089 INFO bedroom_light: 

🤖 Service: light.turn_on
  - entity_id: light.hue_color_lamp_2
  - brightness: 75.40
2022-04-21 23:07:11.903251 INFO bedroom_light: 🎮 Button event triggered: `stop_rotating`
2022-04-21 23:07:11.913208 INFO bedroom_light: 🏃 Running `Predefined (release)` now
2022-04-21 23:07:12.992943 INFO bedroom_light: 🎮 Button event triggered: `start_rotating`
2022-04-21 23:07:13.003502 INFO bedroom_light: 🏃 Running `Predefined (brightness_from_controller_angle)` now
24
up
2022-04-21 23:07:13.022173 INFO bedroom_light: 

🤖 Service: light.turn_on
  - entity_id: light.hue_color_lamp_2
  - brightness: 100.40
2022-04-21 23:07:13.379659 INFO bedroom_light: 

🤖 Service: light.turn_on
  - entity_id: light.hue_color_lamp_2
  - brightness: 125.80
2022-04-21 23:07:13.533407 INFO bedroom_light: 🎮 Button event triggered: `stop_rotating`
2022-04-21 23:07:13.543223 INFO bedroom_light: 🏃 Running `Predefined (release)` now
2022-04-21 23:07:14.249230 INFO bedroom_light: 🎮 Button event triggered: `start_rotating`
2022-04-21 23:07:14.259114 INFO bedroom_light: 🏃 Running `Predefined (brightness_from_controller_angle)` now
12
up
2022-04-21 23:07:14.279930 INFO bedroom_light: 

🤖 Service: light.turn_on
  - entity_id: light.hue_color_lamp_2
  - brightness: 150.40
2022-04-21 23:07:14.628847 INFO bedroom_light: 🎮 Button event triggered: `stop_rotating`
2022-04-21 23:07:14.639090 INFO bedroom_light: 🏃 Running `Predefined (release)` now
2022-04-21 23:07:15.345818 INFO bedroom_light: 🎮 Button event triggered: `start_rotating`
2022-04-21 23:07:15.355238 INFO bedroom_light: 🏃 Running `Predefined (brightness_from_controller_angle)` now
-24
down
2022-04-21 23:07:15.376344 INFO bedroom_light: 

🤖 Service: light.turn_on
  - entity_id: light.hue_color_lamp_2
  - brightness: 175.40
2022-04-21 23:07:15.733046 INFO bedroom_light: 

🤖 Service: light.turn_on
  - entity_id: light.hue_color_lamp_2
  - brightness: 200.80
2022-04-21 23:07:15.869303 INFO bedroom_light: 🎮 Button event triggered: `stop_rotating`
2022-04-21 23:07:15.879935 INFO bedroom_light: 🏃 Running `Predefined (release)` now
2022-04-21 23:07:19.331385 INFO bedroom_light: 🎮 Button event triggered: `start_rotating`
2022-04-21 23:07:19.343454 INFO bedroom_light: 🏃 Running `Predefined (brightness_from_controller_angle)` now
-12
down
2022-04-21 23:07:19.364056 INFO bedroom_light: 

🤖 Service: light.turn_on
  - entity_id: light.hue_color_lamp_2
  - brightness: 225.40
2022-04-21 23:07:19.714718 INFO bedroom_light: 🎮 Button event triggered: `stop_rotating`
2022-04-21 23:07:19.724455 INFO bedroom_light: 🏃 Running `Predefined (release)` now
2022-04-21 23:07:20.764577 INFO bedroom_light: 🎮 Button event triggered: `start_rotating`
2022-04-21 23:07:20.774240 INFO bedroom_light: 🏃 Running `Predefined (brightness_from_controller_angle)` now
-24
down
2022-04-21 23:07:20.794829 INFO bedroom_light: 

🤖 Service: light.turn_on
  - entity_id: light.hue_color_lamp_2
  - brightness: 250.40
2022-04-21 23:07:21.152496 INFO bedroom_light: 

🤖 Service: light.turn_on
  - entity_id: light.hue_color_lamp_2
  - brightness: 255
2022-04-21 23:07:21.324257 INFO bedroom_light: 🎮 Button event triggered: `stop_rotating`
2022-04-21 23:07:21.333995 INFO bedroom_light: 🏃 Running `Predefined (release)` now

Do you have one of these devices in hand @xaviml ?

@xaviml
Copy link
Owner

xaviml commented Apr 21, 2022

Hi @snalty,

You can see now in the logs below even though the angle is -24 and the direction is down the brightness is increasing. Weird bug!

That is, indeed, a weird bug, and I see that direction changes depending if angle is positive or negative... I added this to the integration tests and they are working just fine. I do not have this controller, but I can mock the mqtt payloads from HA. I will test it out myself and see if I can reproduce the bug. Would you mind sharing your configuration in apps.yaml?

Could you also try this on the latest beta release? v4.19.0b4. I do not think it will fix it, but just in case.

Regards,
Xavi M.

@xaviml
Copy link
Owner

xaviml commented Apr 21, 2022

The color of the light sometimes randomy changes?

The color of the light changes when the knob is held. This is the default mapping I added to the controller:

  • 1 click → Toggle
  • 2 click → Full brightness
  • Hold button → Color (temp/xy) with direction changes
  • Left turn → Dim down
  • Right turn → Brighten up

@snalty
Copy link
Author

snalty commented Apr 21, 2022

The color of the light sometimes randomy changes?

The color of the light changes when the knob is held. This is the default mapping I added to the controller:

I have seen that the hold action changes the color however this was occuring during a rotation, I think it might have been because I accidentally set it to homekit adaptive lighting though 😳.

Here is my apps.yaml I've been using for testing:

bedroom_light:
   module: controllerx
   class: ZNXNKG02LMLightController
   integration:
      name: z2m
      listen_to: mqtt
      action_key: action
   controller: smart_knob
   light: light.bedroom_light

Thank you for the work on this project to support this device! It really is an appealing little controller it's just a shame it doesn't seem like it's available for sale right now.

@xaviml
Copy link
Owner

xaviml commented Apr 21, 2022

Thanks, I will keep you updated once I try it out.

@snalty
Copy link
Author

snalty commented Apr 21, 2022

@bartplessers I've found a listing here: https://a.aliexpress.com/_vZo48A

@xaviml
Copy link
Owner

xaviml commented Apr 22, 2022

These are my logs with ControllerX v4.19.0b4 when topic is zigbee2mqtt/smart_knob and payload {"action": "start_rotating", "action_rotation_angle":12}:

2022-04-22 18:15:13.061503 DEBUG bedroom_light: MQTT data event: {'topic': 'zigbee2mqtt/smart_knob', 'wildcard': '#', 'payload': '{"action": "start_rotating", "action_rotation_angle":12}'}
2022-04-22 18:15:13.065683 INFO bedroom_light: 🎮 Button event triggered: `start_rotating`
2022-04-22 18:15:13.070412 DEBUG bedroom_light: Extra:
{'action': 'start_rotating', 'action_rotation_angle': 12}
2022-04-22 18:15:13.076922 INFO bedroom_light: 🏃 Running `Predefined (brightness_from_controller_angle)` now
2022-04-22 18:15:13.081749 DEBUG bedroom_light: `brightness_from_controller_angle` is not recognized as a template
2022-04-22 18:15:13.088212 DEBUG bedroom_light: `light.livingroom` is not recognized as a template
2022-04-22 18:15:13.091336 DEBUG bedroom_light: get state: light.livingroom, {} from bedroom_light
2022-04-22 18:15:13.096842 DEBUG bedroom_light: Attribute value before running the hold action: 5.0
2022-04-22 18:15:13.101258 DEBUG bedroom_light: Going direction: up
2022-04-22 18:15:13.106672 DEBUG bedroom_light: `light.livingroom` is not recognized as a template
2022-04-22 18:15:13.109111 INFO bedroom_light: 
🤖 Service: light.turn_on
  - entity_id: light.livingroom
  - brightness: 30.40
2022-04-22 18:15:13.110111 DEBUG bedroom_light: call_service: light/turn_on, {'entity_id': 'light.livingroom', 'brightness': 30.4}
2022-04-22 18:15:13.467378 DEBUG bedroom_light: `light.livingroom` is not recognized as a template
2022-04-22 18:15:13.469869 INFO bedroom_light: 
🤖 Service: light.turn_on
  - entity_id: light.livingroom
  - brightness: 55.80
2022-04-22 18:15:13.470907 DEBUG bedroom_light: call_service: light/turn_on, {'entity_id': 'light.livingroom', 'brightness': 55.8}
2022-04-22 18:15:13.830508 DEBUG bedroom_light: `light.livingroom` is not recognized as a template
2022-04-22 18:15:13.837729 INFO bedroom_light: 
🤖 Service: light.turn_on
  - entity_id: light.livingroom
  - brightness: 81.20
2022-04-22 18:15:13.840236 DEBUG bedroom_light: call_service: light/turn_on, {'entity_id': 'light.livingroom', 'brightness': 81.2}

These are the logs when topic is zigbee2mqtt/smart_knob and payload is {"action": "start_rotating", "action_rotation_angle":-12}:

2022-04-22 18:15:14.190116 DEBUG bedroom_light: MQTT data event: {'topic': 'zigbee2mqtt/smart_knob', 'wildcard': '#', 'payload': '{"action": "stop_rotating"}'}
2022-04-22 18:15:14.191944 INFO bedroom_light: 🎮 Button event triggered: `stop_rotating`
2022-04-22 18:15:14.193864 DEBUG bedroom_light: Extra:
{'action': 'stop_rotating'}
2022-04-22 18:15:14.198026 INFO bedroom_light: 🏃 Running `Predefined (release)` now
2022-04-22 18:15:14.199853 DEBUG bedroom_light: `release` is not recognized as a template
2022-04-22 18:15:19.233689 DEBUG bedroom_light: MQTT data event: {'topic': 'zigbee2mqtt/smart_knob', 'wildcard': '#', 'payload': '{"action": "start_rotating", "action_rotation_angle":-12}'}
2022-04-22 18:15:19.237839 INFO bedroom_light: 🎮 Button event triggered: `start_rotating`
2022-04-22 18:15:19.242514 DEBUG bedroom_light: Extra:
{'action': 'start_rotating', 'action_rotation_angle': -12}
2022-04-22 18:15:19.248256 INFO bedroom_light: 🏃 Running `Predefined (brightness_from_controller_angle)` now
2022-04-22 18:15:19.252753 DEBUG bedroom_light: `brightness_from_controller_angle` is not recognized as a template
2022-04-22 18:15:19.258937 DEBUG bedroom_light: `light.livingroom` is not recognized as a template
2022-04-22 18:15:19.261717 DEBUG bedroom_light: get state: light.livingroom, {} from bedroom_light
2022-04-22 18:15:19.267014 DEBUG bedroom_light: Attribute value before running the hold action: 81.0
2022-04-22 18:15:19.271585 DEBUG bedroom_light: Going direction: down
2022-04-22 18:15:19.274887 DEBUG bedroom_light: `light.livingroom` is not recognized as a template
2022-04-22 18:15:19.277328 INFO bedroom_light: 
🤖 Service: light.turn_on
  - entity_id: light.livingroom
  - brightness: 106.40
2022-04-22 18:15:19.278196 DEBUG bedroom_light: call_service: light/turn_on, {'entity_id': 'light.livingroom', 'brightness': 106.4}
2022-04-22 18:15:19.633838 DEBUG bedroom_light: `light.livingroom` is not recognized as a template
2022-04-22 18:15:19.636326 INFO bedroom_light: 
🤖 Service: light.turn_on
  - entity_id: light.livingroom
  - brightness: 131.80
2022-04-22 18:15:19.637318 DEBUG bedroom_light: call_service: light/turn_on, {'entity_id': 'light.livingroom', 'brightness': 131.8}
2022-04-22 18:15:19.993388 DEBUG bedroom_light: `light.livingroom` is not recognized as a template
2022-04-22 18:15:19.996913 INFO bedroom_light: 
🤖 Service: light.turn_on
  - entity_id: light.livingroom
  - brightness: 157.20
2022-04-22 18:15:19.998230 DEBUG bedroom_light: call_service: light/turn_on, {'entity_id': 'light.livingroom', 'brightness': 157.2}
2022-04-22 18:15:20.338204 DEBUG bedroom_light: MQTT data event: {'topic': 'zigbee2mqtt/smart_knob', 'wildcard': '#', 'payload': '{"action": "stop_rotating"}'}
2022-04-22 18:15:20.340016 INFO bedroom_light: 🎮 Button event triggered: `stop_rotating`
2022-04-22 18:15:20.341995 DEBUG bedroom_light: Extra:
{'action': 'stop_rotating'}
2022-04-22 18:15:20.344671 INFO bedroom_light: 🏃 Running `Predefined (release)` now
2022-04-22 18:15:20.346608 DEBUG bedroom_light: `release` is not recognized as a template

I confirm I experience the same as you @snalty. I will investigate why is this.

Regards,
Xavi M.

@xaviml
Copy link
Owner

xaviml commented Apr 22, 2022

Also, you can add log_level: DEBUG in the configuration to see debug logs:

bedroom_light:
   log_level: DEBUG
   module: controllerx
   class: ZNXNKG02LMLightController
   integration:
      name: z2m
      listen_to: mqtt
      action_key: action
   controller: smart_knob
   light: light.bedroom_light

@xaviml
Copy link
Owner

xaviml commented Apr 22, 2022

Hi @snalty,

I pushed new code that should have fixed the problem. I added tests for this specific use case and confirmed is working, but I would appreciate it if you can try it out.

I just released ControllerX v4.19.0b5 version, which you can download from HACS.

Regards,
Xavi M.

@xaviml
Copy link
Owner

xaviml commented Apr 29, 2022

This device has been added in ControllerX v4.19.0.

@xaviml xaviml closed this as completed Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-device New device
Projects
None yet
Development

No branches or pull requests

3 participants