Trying to automate MOES Tuya Smart Knob

hi all. I’m trying to setup automation with MOES Tuya Smart Knob TuYa ERS-10TZBVK-AA control via MQTT | Zigbee2MQTT

For a simple start, I use this yml:

alias: Bedroom smart knob
description: ""
trigger:
  - platform: device
    domain: mqtt
    device_id: 23f14bb9c488ca27cba9f11bf5b8870c
    type: action
    subtype: toggle
    discovery_id: 0xe0798dfffe9c1c40 action_toggle
condition: []
action:
  - service: light.toggle
    data: {}
    target:
      entity_id:
        - light.yeelink_color1_cb8d_light
mode: single

The first problem I face is: if there are ~2 seconds interval between button toggle, the lights won’t respond. As if I have to wait for 10 seconds between presses to get the lights to toggle on/off.
If there a way to buffer the toggle events so I don’t have to press repeatedly to toggle the lights?

So I decided to use a blueprint, but the blueprint doesn’t list the MOES smart knob:

So I can’t really utilize the blueprint, and trying to set automation manually, I can’t get the lights to toggle quickly nor can I find all the options to utilize the knob rotation functions.

Can anyone please help?

Im using this automation. Idea is invented by someone else on our forum, however can not find it when I search. Sorry, I can not give credit to the right person.

However, it works quite well. Remember the device need a name with no spaces, otherwise it will not tirgger, and the knob need to be in command mode, done in Z2M interface.

The below is including my commands, for inspiration.

alias: Storstue Tuay Smart Knob (Command mode)
description: ""
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/storstuekontaktlightknop
condition: []
action:
  - variables:
      command: "{{ trigger.payload_json.action }}"
      size: "{{ trigger.payload_json.action_step_size }}"
  - choose:
      - conditions: "{{ trigger.payload_json.action == 'toggle' }}"
        sequence:
          - type: toggle
            device_id: 94f95053730dbe60e4a6311698fb0ea0
            entity_id: light.storstue_all
            domain: light
      - conditions: "{{ command == 'brightness_step_up' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Storstue All/set
              payload: >
                {"brightness_step_onoff": {{( size *
                0.5)|round}},"transition":0.1 }
      - conditions: "{{ command == 'brightness_step_down'  }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Storstue All/set
              payload: |
                {"brightness_step": -{{( size * 0.5)|round}},"transition":0.1 }
      - conditions: "{{ command == 'color_temperature_step_up' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Storstue All/set
              payload: |
                {"color_temp_step": {{ size * 0.5}},"transition":0.1 }
      - conditions: "{{ command == 'color_temperature_step_down' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/Storstue All/set
              payload: |
                {"color_temp_step": -{{ size * 0.5 }},"transition":0.1 }
mode: queued
max_exceeded: silent
max: 10

Thanks. I’m still trying to learn how to write automation. It’s very difficult.
however, even after I renamed the devices with no spaces, they don’t appear in the Remote: Devices blueprint drop down menu

This is not a blueprint.

Steps: It is quite simple, even it might sound complicated.

  1. Create a new blank automation
  2. Go to “yaml mode”
  3. Paste my automation in
  4. Go to GUI mode again to make simpler changes
  5. In Trigger section, change to your tuya knob device name. Mine is called “storstuekontaktlightknop”
  6. In option 1, change to you light/bulb. Just chose it from the dropdown list
  7. In option 2-Option5
    7a) Change this name “Storstue All” into the name of you light/bulb
  8. Save the automation

Then it will work.

Thank you for the detailed explanation.
For option 2-5, I cannot use it in this way because the light is a Yeelight (Xiaomi) and it’s not using an MQTT service.

I still cannot see my devices in blueprint mode.

Ok, was not aware your light was not in zigbee2mqtt.

The blueprint you show in the first post is a ZHA blueprint, and not a Zigbee2Mqtt blueprint. It will not work. You need a blueprint for Z2M

oh, I wasn’t aware there was a difference between ZHA and Z2M.
I use a Zigbee dongle v.3 connected to the server that runs HA.
And I use the MQTT broker addon, as well as an ESP32 BT proxy.

So I need to filter blueprints for Z2M?

hi again,

I gave it another shot since I repalced my yeelight with this: TuYa TS0505B_1 control via MQTT | Zigbee2MQTT

It almost works as expected, but I wasn’t able to fix some of the things. Maybe you can help again?

  1. the brightness steps is either 100% bright or 10% bright, there’s no gradual move between the values.
  2. Same with color temp. no gradual move on color temp.

Can you please assist?

here are my modifications to your automation:

alias: BulbTuya Smart Knob (Command mode)
description: ""
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/smart_knob
condition: []
action:
  - variables:
      command: "{{ trigger.payload_json.action }}"
      size: "{{ trigger.payload_json.action_step_size }}"
  - choose:
      - conditions: "{{ trigger.payload_json.action == 'toggle' }}"
        sequence:
          - type: toggle
            device_id: b48e9b2ab0e8a164cd97214dbe06bc56
            entity_id: 19683080b17cc83dec3929cae15f19b8
            domain: light
      - conditions: "{{ command == 'brightness_step_up' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/bulb_bedroom/set
              payload: >
                {"brightness_step_onoff": {{( size *
                0.2)|round}},"transition":0.1 }
      - conditions: "{{ command == 'brightness_step_down'  }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/bulb_bedroom/set
              payload: |
                {"brightness_step": -{{( size * 0.5)|round}},"transition":0.1 }
      - conditions: "{{ command == 'color_temperature_step_up' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/bulb_bedroom/set
              payload: |
                {"color_temp_step": {{ size * 0.5}},"transition":0.1 }
      - conditions: "{{ command == 'color_temperature_step_down' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/bulb_bedroom/set
              payload: |
                {"color_temp_step": -{{ size * 0.5 }},"transition":0.1 }
mode: queued
max_exceeded: silent
max: 10

p.s. how did you learn to create this kind of yaml?

Hi Gil, Not sure how/why I did not see your post. It came up in the list today. It is a long time ago, did you get it to work?

Hi. Not exactly, it doesn’t work as expected.

  1. When trying to get to the lowest possible brightness value, it will still be very bright when comparing against using the brightness slider in HA UI.
  2. Rotating the knob to get to the lowest brightness value will turn off the light instead of remaining on the lowest value.
  3. Same with the highest value, seems that rotating the know won’t get the light as bright as it can be as compared to when I do it via HA UI.

This is my really messed up automation that works to some extent:

alias: Master bedroom - Dimmer MOES Smart Knob
description: For bedroom zigbee light
trigger:
  - platform: device
    domain: mqtt
    device_id: 23f14bb9c488ca27cba9f11bf5b8870c
    type: action
    subtype: brightness_step_up
    discovery_id: 0xe0798dfffe9c1c40 action_brightness_step_up
    id: "2"
  - platform: device
    domain: mqtt
    device_id: 23f14bb9c488ca27cba9f11bf5b8870c
    type: action
    subtype: brightness_step_down
    discovery_id: 0xe0798dfffe9c1c40 action_brightness_step_down
    id: "3"
  - platform: device
    domain: mqtt
    device_id: 23f14bb9c488ca27cba9f11bf5b8870c
    type: action
    subtype: toggle
    discovery_id: 0xe0798dfffe9c1c40 action_toggle
    id: "1"
  - platform: device
    domain: mqtt
    device_id: 23f14bb9c488ca27cba9f11bf5b8870c
    type: action
    subtype: color_temperature_step_down
    discovery_id: 0xe0798dfffe9c1c40 action_color_temperature_step_down
    id: color_temp_cool
    enabled: false
  - platform: mqtt
    topic: zigbee2mqtt/smart_knob
    enabled: true
condition: []
action:
  - if:
      - condition: trigger
        id:
          - "1"
    then:
      - service: light.toggle
        data:
          brightness_pct: 100
          transition: 2
          kelvin: 2000
        target:
          entity_id: light.0xa4c138cd23d48242
    else:
      - if:
          - condition: trigger
            id:
              - "2"
            alias: Brightness_Step_Up
        then:
          - device_id: f6565744d60fa93366b03702500ca1f2
            domain: light
            entity_id: 544da56a4e4f4f3f44f1c2bb95eba201
            type: brightness_increase
        else:
          - if:
              - condition: trigger
                id:
                  - "3"
                alias: Brightness_Step_Down
            then:
              - device_id: f6565744d60fa93366b03702500ca1f2
                domain: light
                entity_id: 544da56a4e4f4f3f44f1c2bb95eba201
                type: brightness_decrease
  - variables:
      command: "{{ trigger.payload_json.action }}"
      size: "{{ trigger.payload_json.action_step_size }}"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ command == 'color_temperature_step_down' }}"
            alias: "color temp step down "
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/bedroom_zb_light/set
              payload: |
                {"color_temp_move": -100 }
      - conditions:
          - condition: template
            value_template: "{{ command == 'color_temperature_step_up' }}"
        sequence:
          - service: mqtt.publish
            data:
              topic: zigbee2mqtt/bedroom_zb_light/set
              payload: |
                {"color_temp_move": 100 }
mode: queued
max_exceeded: silent
max: 10

Hi Gil,
Below I have tried to change my automation to use HA command “light.on” instead of the MQTT version. I works, however is not optimal in any way. Might be able to optimise it further using templates, however not sure. My version will give some flash up/down when turning the knob continually. It works perfectly if done very slowly (however, who is ever doing that:-))

So, my best suggestion is the MQTT commands version.

Here my test automation

alias: Storstuetuyaknoptest2
description: ""
trigger:
  - platform: mqtt
    topic: zigbee2mqtt/storstuekontaktlightknop
condition: []
action:
  - variables:
      command: "{{ trigger.payload_json.action }}"
      size: "{{ trigger.payload_json.action_step_size }}"
  - choose:
      - conditions: "{{ trigger.payload_json.action == 'toggle' }}"
        sequence:
          - type: toggle
            device_id: 94f95053730dbe60e4a6311698fb0ea0
            entity_id: light.storstue_all
            domain: light
      - conditions: "{{ command == 'brightness_step_up' }}"
        sequence:
          - service: light.turn_on
            data:
              brightness_step_pct: 5
            target:
              entity_id: light.storstuelightgroup
      - conditions: "{{ command == 'brightness_step_down'  }}"
        sequence:
          - service: light.turn_on
            data:
              brightness_step_pct: -5
            target:
              entity_id: light.storstuelightgroup
mode: single
max_exceeded: silent

1 Like

ZHA default’s entity trigger for the Moes Smart Knob shows these triggers (rotation filtered):

  • “right” device_rotated_slow
  • “left” device_rotated_slow
  • “right” device_rotated_fast ← never triggered
  • “left” device_rotated_fast ← never triggered
  • Device rotated “Right” ← never triggered
  • Device rotated “Left” ← never triggered

Only the slow ones are triggered, so I falled back on using a manual trigger.
Here is how I managed the dimming with a zha event, and this automation works perfectly fine for me:

alias: Room 1 - Dimmer step
trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: d0ecf2fed74hd47hb069b49ad8
condition:
  - condition: template
    value_template: "{{ trigger.event.data.command == 'step' }}"
#   ^ This captures any rotation event ^
action:
  - service: light.turn_on
#   ^ This service allows to set an exact brightness
    data:
      brightness_step_pct: >
        {{ (1 if trigger.event.data.params.step_mode == 0 else -1) *
        trigger.event.data.params.step_size }}
#       ^ This increases/decreases the brightness
#         in function of the exact amount rotated
      transition: 0.1
    target:
      entity_id: light.room_1
mode: single

Replace d0ecf2fed74hd47hb069b49ad8 by the real device_id of your dimmer.

Of course one can still multiply trigger.event.data.params.step_size by any factor to get the desired brightness modifier, but I found the returned amount quite satisfying.

For more details you can listen to the zha_event in Developper tools > Events > Listen to events > “zha_event”. Here is an example of what is returned:

event_type: zha_event
data:
# [...]
  device_id: d0ecf2fed74hd47hb069b49ad8 # <- Your device
  endpoint_id: 1
  cluster_id: 8
  command: step # <- The step command
  args:
    - 0
    - 13
    - 1
  params:
    step_mode: 0 # <- 0 for right, 1 for left
    step_size: 13 # <- Amount rotated (seems to be the degree angle)
    transition_time: 1
    options_mask: null
    options_override: null
# [...]

I looking a smooth brightness automition for mine Meos knob, but when I check my events it says the command: rotate_type

It is not a event type. The knob have 2 modes of operation. The command mode and the event mode. For the above automations to work it needs to be in command mode. It’s done in the Z2M interface.

Wasn’t you I want to quote… I’m using ZHA… sorry

Hi glide, I try this but my event list command as rotate_right/left, not step
how did you change the knob to command mode with ZHA?