merdok / homebridge-miot

Homebridge plugin for devices supporting the Xiaomi miot protocol
MIT License
364 stars 62 forks source link

Sensor to Light Switch remapping #535

Closed 350d closed 7 months ago

350d commented 8 months ago

Describe the idea or improvement There is a clever solution available to use window/door sensor as smart light switch where some alias workaround needed to convert sensor to switch. Home Assistant example:

- alias: Light switch
  trigger:
    platform: state
    entity_id: binary_sensor.door_window_sensor_158d000xxxxxc2
  action:
    service: light.toggle
    entity_id: light.somelight

Describe the solution you'd like Is there any options already available to do that with this plugin or additional development needed?

Additional context No context.

merdok commented 8 months ago

Hi, interesting to use of the sensors😅 I understand using the sensor as a trigger to turn on off a light switch is not possible hence this hack? I do not think that it is possible currently, but I mean you could try to manually specify the device model and use properly monitor or control to expose the properties which you want. The thing is that probably the properties will not match between the real or fake device, but you could try that out anyway...

350d commented 8 months ago

@merdok Thank you! Can you help me with that? How to manually specify the device?

merdok commented 8 months ago

Please read the README, all the information which you need is there!

350d commented 8 months ago

I already did, but it's way out of my knowledge in this area. Any examples available for remapping one device type to another? Appreciate your help here.

Sensor details:

NAME:     Light switch Virtual
ID:       lumi.158d00016cd97a
MODEL:    lumi.sensor_magnet.v2

PROPS:

magnet-sensor:contact-state

EVENTS:

magnet-sensor:close
magnet-sensor:open
magnet-sensor:door-not-closed
battery:low-battery
merdok commented 8 months ago

You have to specify the device type manually in the config. That will be used to create the accessory. Afterwards, as the properties will it match between what you specified and the actual device, you should propertyMonitor or propertyControl to configure the device. All the info on how to do that is in the README. You have to also access the miot spec for your device to see what properties are there.