syssi / xiaomi_raw

Custom component for Home Assistant to faciliate the reverse engeneering of Xiaomi MiIO devices
Apache License 2.0
107 stars 20 forks source link

Can't add multiple switches #20

Open Ranchuking opened 2 years ago

Ranchuking commented 2 years ago

Hello, when I add multi switches in the config yaml. I only get one in the entity.

switch:

syssi commented 2 years ago

This is strange. I will give it a try tomorrow. It should be possible.

syssi commented 2 years ago

You are right. The issue is the unique_id which is the model name + mac_address + state_property f.e. philips.light.candle-78:11:DC:04:ED:EA-power. I was able to reproduce the issue with this configuration:


switch:
  - platform: xiaomi_miio_raw
    name: device a switch 1
    host: 192.168.1.238
    token: 36574882f3d245d693549df4cf56aeb6
    turn_on_command: 'set_power'
    turn_on_parameters: 'on'
    turn_off_command: 'set_power'
    turn_off_parameters: 'off'
    state_property: 'power'
    state_property_getter: 'get_prop'
    state_on_value: 'on'
    state_off_value: 'off'
  - platform: xiaomi_miio_raw
    name: device a switch 2
    host: 192.168.1.238
    token: 36574882f3d245d693549df4cf56aeb6
    turn_on_command: 'set_power'
    turn_on_parameters: 'on'
    turn_off_command: 'set_power'
    turn_off_parameters: 'off'
    state_property: 'power'
    state_property_getter: 'get_prop'
    state_on_value: 'on'
    state_off_value: 'off'

This is the error:

2021-12-20 18:24:08 ERROR (MainThread) [homeassistant.components.switch] Platform xiaomi_miio_raw does not generate unique IDs. ID philips.light.candle-78:11:DC:04:ED:EA-power already exists - ignoring switch.device_a_switch_1

May be we should make the unique_id optional.