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

[Help wanted] Failed to add 'ZXFANS F2 smart knob remote control' device by myself #1391

Open
kalenty opened this issue Jun 30, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request

Comments

@kalenty
Copy link
Contributor

kalenty commented Jun 30, 2024

I had some problems when trying to customize an unsupported device (ZXFANS F2 smart knob remote control). I found the spec page for this device: 'https://home.miot-spec.com/spec/ailol.remote.ts4', and then tried to add my own converter in the config folder:
/homeassistant/xiaomi_gateway3.py

from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [{
    18250: ["ZXFANS", "ZXFANS F2 smart knob remote control", "ailol.remote.ts4"],
    "spec": [
        BaseConv("battery", "sensor", mi="5.p.1003"),
        BaseConv("switch", "sensor", mi="5.p.1"),
        BaseConv("mode", "sensor", mi="5.p.1020"),
    ]
}] + DEVICES

After adding it, I found that the device added the sensor corresponding to the battery, but there was no specific content, and the other monitoring properties added did not get the content, even if I triggered the button. At the same time, other defined BLE devices, such as 'Mijia Smart Temperature and Humidity Monitor', are working normally.
image

For the problem of battery not displaying, I tried to check the log. In /homeassistant/homeassistant.log, it seems that there is no relevant log content except the loaded log, but the log of Humidity Monitor is there (I have turned on the integrated debug log):

2024-06-30 14:12:32.495 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.192.168.0.108] {'uid': '78da07f2cfe1', 'did': 'blt.3.1i403l524k400', 'msg': 'init_device', 'data': {'did': 'blt.3.1i403l524k400', 'type': 'ble', 'mac': '78:da:07:f2:cf:e1', 'cloud_name': 'ZXFANS F2 smart knob remote control', 'cloud_fw': '2.1.1_0015', 'market_brand': 'ZXFANS', 'market_name': 'ZXFANS F2 smart knob remote control', 'market_model': 'ailol.remote.ts4'}}
2024-06-30 14:12:32.496 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.192.168.0.108] {'uid': '78da07f2cfe1', 'did': 'blt.3.1i403l524k400', 'msg': 'add_device'}
2024-06-30 14:12:32.497 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.192.168.0.108] {'uid': '78da07f2cfe1', 'did': 'blt.3.1i403l524k400', 'msg': 'add_entity', 'entity': 'sensor.78da07f2cfe1_battery'}
2024-06-30 14:12:32.499 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.192.168.0.108] {'uid': '78da07f2cfe1', 'did': 'blt.3.1i403l524k400', 'msg': 'add_entity', 'entity': 'sensor.78da07f2cfe1_switch'}
2024-06-30 14:12:32.501 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.192.168.0.108] {'uid': '78da07f2cfe1', 'did': 'blt.3.1i403l524k400', 'msg': 'add_entity', 'entity': 'sensor.78da07f2cfe1_mode'}
2024-06-30 14:12:32.502 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.192.168.0.108] {'uid': '78da07f2cfe1', 'did': 'blt.3.1i403l524k400', 'msg': 'add_entity', 'entity': 'select.78da07f2cfe1_command'}
2024-06-30 14:12:32.504 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.192.168.0.108] {'uid': '78da07f2cfe1', 'did': 'blt.3.1i403l524k400', 'msg': 'add_entity', 'entity': 'sensor.78da07f2cfe1_ble'}
2024-06-30 14:12:32.531 DEBUG (MainThread) [custom_components.xiaomi_gateway3.gate.192.168.0.108] {'msg': 'MQTT connected'}
2024-06-30 14:12:33.253 DEBUG (MainThread) [custom_components.xiaomi_gateway3.mqtt.192.168.0.108] {'topic': 'central/report', 'data': b'{"id":205690648,"_to":128,"type":6,"method":"properties_changed","params":[{"did":"blt.3.1g76j5r9c4g01","siid":3,"piid":1001,"value":27.000000,"tid":25}]}'}

For the problem of knob/button not displaying, I checked wiki - Converters, I don't understand how to define the trigger of the knob/button through the device piid. In the examples of devices.py, it seems that many are triggered by siid, but I don't know where the mi spec of 'x.e.x' is obtained (the spec page provided initially seems to have only piid). I suspect that there is a problem with the converter I wrote, but I don't know where the problem is.

I hope someone can give me some tips on related operations or document links. I would be grateful.

@kalenty kalenty changed the title Failed to add 'ZXFANS F2 smart knob remote control' device by myself Failed to add 'ZXFANS F2 smart knob remote control' device by myself [help wanted] Jun 30, 2024
@kalenty kalenty changed the title Failed to add 'ZXFANS F2 smart knob remote control' device by myself [help wanted] [Help wanted] Failed to add 'ZXFANS F2 smart knob remote control' device by myself Jun 30, 2024
@kalenty
Copy link
Contributor Author

kalenty commented Jun 30, 2024

found similar config of another knob and tried it in self converter (and fix battery spec error)

DEVICES = [{
    # https://home.miot-spec.com/spec/ailol.remote.ts4
    18250: ["zxf", "ZXFANS F2 smart knob remote control", "ailol.remote.ts4"],
    "spec": [
        BaseConv("battery", "sensor", mi="4.p.1003"),
        BaseConv("action", "sensor"),
        MapConv("action", mi="5.e.1012.p.1", map={1:: BUTTON_1_SINGLE, 2: BUTTON_2_SINGLE, 3: BUTTON_3_SINGLE, 4: BUTTON_4_SINGLE, 5: "knob_increasing", 6: "knob_reduced"),
        MapConv("action", mi="5.e.1013.p.1", map={1: BUTTON_1_DOUBLE, 2: BUTTON_2_DOUBLE, 3: BUTTON_3_DOUBLE, 4: BUTTON_4_DOUBLE}),
        MapConv("action", mi="5.e.1014.p.1", map={1: BUTTON_1_HOLD, 2: BUTTON_2_HOLD, 3: BUTTON_3_HOLD, 4: BUTTON_4_HOLD}),
    ]
}] + DEVICES

restart hass, but nothing change.

delete the device, then add it back, tried

DEVICES = [{
    # https://home.miot-spec.com/spec/ailol.remote.ts4
    18250: ["ZXFANS", "ZXFANS F2 smart knob remote control", "ailol.remote.ts4"],
    "spec": [
        BaseConv("battery", "sensor", mi="4.p.1003"),
    ]
}] + DEVICES

the battery still no resp

@kalenty
Copy link
Contributor Author

kalenty commented Jul 1, 2024

After a day passed, I reopened the Gateway3 integration of HomeAssistant, and it seems that the Battery was updated 20 hours ago 🥲. I guess it is because after the modification of this script is saved, it doesn't take effect immediately? Or because of the device, the frequency of updating the Battery is very low.

@kalenty
Copy link
Contributor Author

kalenty commented Jul 1, 2024

success!

from custom_components.xiaomi_gateway3.core.devices import *

DEVICES = [{
    # https://home.miot-spec.com/spec/ailol.remote.ts4
    18250: ["ZXFANS", "ZXFANS F2 smart knob remote control", "ailol.remote.ts4"],
    "spec": [
        BaseConv("battery", "sensor", mi="4.p.1003"),
        BaseConv("action", "sensor"),
        MapConv("action", mi="5.e.1012.p.1", map={1: BUTTON_1_SINGLE, 2: BUTTON_2_SINGLE, 3: BUTTON_3_SINGLE, 4: BUTTON_4_SINGLE, 5: "knob_increasing", 6: "knob_reduced"}),
        MapConv("action", mi="5.e.1013.p.1", map={1: BUTTON_1_DOUBLE, 2: BUTTON_2_DOUBLE, 3: BUTTON_3_DOUBLE, 4: BUTTON_4_DOUBLE}),
        MapConv("action", mi="5.e.1014.p.1", map={1: BUTTON_1_HOLD, 2: BUTTON_2_HOLD, 3: BUTTON_3_HOLD, 4: BUTTON_4_HOLD}),
    ]
}] + DEVICES

It seems that I accidentally added a semicolon in the script above, which caused an error. Download the diagnostic information to see the specific error.

Now my only question is, how is this 5.e.xxx parsed from the spec?

@kalenty
Copy link
Contributor Author

kalenty commented Jul 1, 2024

pr here #1393

@xiasi0
Copy link

xiasi0 commented Jul 2, 2024

我直接在devices里边改了。体验不太好。不能连续旋转。旋转间隔还不能太短。转一下要等等。

@kalenty
Copy link
Contributor Author

kalenty commented Jul 3, 2024

我直接在devices里边改了。体验不太好。不能连续旋转。旋转间隔还不能太短。转一下要等等。

@xiasi0 你的使用方式是怎么样的? 我这边的情况是, 假如自动化(automation)监听旋钮 action 的状态, 在按钮触发的时候它会快速触发(trigger)两次状态变换, 但是 action 的值都是对应的按钮, 导致我不得不针对点击类型的按钮做了一个 timer 来防止 1s 内连续触发. 旋转倒是不用等, 只是自动化的设置需要修改模式从 single -> parallel(max:5)
-- 不知道有没有办法可以只监听 event, 而不是监听状态变化

@xiasi0
Copy link

xiasi0 commented Jul 5, 2024

我直接在devices里边改了。体验不太好。不能连续旋转。旋转间隔还不能太短。转一下要等等。

你的使用方式是怎么样的?我这边的情况是, 假如自动化(automation)监听旋钮 action 的状态, 在按钮触发的时候它会快速触发(trigger)两次状态变换, 但是 action 的值都是对应的按钮做了一个, 导致我不得不针对点击类型的按钮 timer 来防止 1s 内连续触发.旋转倒是不用等, 只是自动化的设置需要修改模式从 single -> parallel(max:5) -- 不知道有没有办法可以只监听 event, 而不是监听状态变化

四个按键体验还可以,就是四个无线按钮。就是这个旋转,只有开始旋转才上报一个knob_increasing或者knob_reduced。你必须停下旋稍等一下,再次开始旋转才会上报第二个旋转状态。它不是连续的。
这是自动化我只用按键没有用旋转,不太好用,跟个按键差不多。如果好的用法请回复我

alias: 智有范四键旋钮
description: ""
trigger:
  - platform: state
    entity_id: sensor.38d2ca321c9b_action
    to:
      - button_1_single
      - button_2_single
      - button_3_single
      - button_4_single
      - button_1_double
      - button_2_double
      - button_3_double
      - button_4_double
      - button_1_hold
      - button_2_hold
      - button_3_hold
      - button_4_hold
      - knob_increasing
      - knob_reduced
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == \"button_1_single\" }}"
        sequence:
          - service: light.toggle
            data: {}
            target:
              entity_id: light.1
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == \"button_2_single\" }}"
        sequence:
          - service: light.toggle
            data: {}
            target:
              entity_id: light.2
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == \"button_3_single\" }}"
        sequence:
          - service: light.toggle
            data: {}
            target:
              entity_id: light.3
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state == \"button_4_single\" }}"
        sequence:
          - service: light.toggle
            target:
              entity_id: light.4
            data: {}
mode: single

@kalenty
Copy link
Contributor Author

kalenty commented Jul 7, 2024

@xiasi0 确实如此, 我与客服咨询了一下, 确认是由于米家的限制, 导致旋钮类的设备无法连续多次触发, 即无法无极调节; 假如使用乐式芯片则可以直连, 但是这与HA就没有什么关系了
假如还是使用米家网关接入, 又想要类似的效果, 客服提供的方案是这样: https://b23.tv/BacCzic -- 启动旋钮以后起一个持续降低数值的脚本, 点击按钮停止

I consulted with the customer service and confirmed that it was due to the limitation of Mijia that the knob-type devices could not be triggered multiple times continuously, that is, they could not be adjusted infinitely; if you use the Leshi chip, you can connect directly, but this has nothing to do with HA. If you still use the Mijia gateway to access and want a similar effect, the solution provided by the customer service is as follows: https://b23.tv/BacCzic -- After starting the knob, a script will be started to continuously reduce the value, and click the button to stop

@AlexxIT AlexxIT added the enhancement New feature or request label Jul 13, 2024
@AlexxIT AlexxIT self-assigned this Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants