zizi4n5 / homebridge-switchbot-for-mac

Homebridge SwitchBot is plugin for Homebridge that allows you to manage SwitchBot.
MIT License
18 stars 3 forks source link

Feature Request: Single device on/off with timer #12

Closed benjaminbogdanovic closed 3 years ago

benjaminbogdanovic commented 4 years ago

Thanks for your work on this project so far! All the others I have come across use gatttool, so are Linux only.

Would it be possible to have single device on and off as shown in the screenshot, with a normal mode, and an add on mode. This would be useful for light switches.

A timer for how long it should stay on for would also be useful, a 'press' mode. I am seeing a use case for an intercom that opens a door, similar to this using the Lock accessory type: https://github.com/github9984/homebridge-switchbot-lock. Thank you in advance if you find this worthy of your time.

Screenshot 2020-06-27 at 01 47 21
benjaminbogdanovic commented 4 years ago

Would using the same MAC address for on and off on the current setup work?

zizi4n5 commented 4 years ago

If you want to use it with a single device, you can have the same address specified for on and off, but just specify the MAC address directly as shown below and it will work. (Internally, it works by specifying the same MAC address for on and off.

https://github.com/zizi4n5/homebridge-switchbot-for-mac#control-one-switchbot

benjaminbogdanovic commented 4 years ago

Thanks for your response. That makes sense. I have not not received my switchbot yet, it is arriving later today, but I wanted to understand the functionality of this plugin, but was confused by the reference to two devices in the Properties section on the readme.

zizi4n5 commented 4 years ago

Thanks for your comment. I feel it's hard to explain one device and two devices, so I'll add an image, etc. and improve it.

zizi4n5 commented 4 years ago

Would it be possible to have single device on and off as shown in the screenshot, with a normal mode, and an add on mode. This would be useful for light switches.

There is no option to change the mode in the plugin. So the SwitchBot device will work in the mode that is set SwitchBot app. Try changing the mode of your device in the SwitchBot app. https://www.switch-bot.com/bot

zizi4n5 commented 4 years ago

Press-hold Time can be set in the SwitchBot app too.

IMG_9485

benjaminbogdanovic commented 4 years ago

That's good to know. I was unaware that it listens to the in app settings. My experience with other hardware such as the Broadlink RM is quite the opposite. The plugin usually has to set these things.

Would HomeKit know if the switchbot is on or off using that setting in the app?

I am currently looking at the code an attempting to convert it from a switch accessory to a lock accessory. I am hoping it will be simple enough.

zizi4n5 commented 4 years ago

Would HomeKit know if the switchbot is on or off using that setting in the app?

HomeKit cannot know what settings you have in the app, but if you change the settings in the SwitchBot app, the SwitchBot device will reflect the changes.

Then, the SwitchBot device will behave according to the device's settings when HomeKit sends on or off.

zizi4n5 commented 4 years ago

This plugin uses the node-switchbot's turnOn/turnOff methods. This method works according to the settings of the SwitchBot device. https://github.com/futomi/node-switchbot#turnon-method

Then there's also the press/down/up methods, so it looks like I could add a set mode option to the plugin. However, I'm not sure if this is a limitation of node-switchbot or the SwitchBot API, but node-switchbot does not support press timers.

benjaminbogdanovic commented 4 years ago

Sorry, I phrased that question poorly. For example, if the press mode with a timer for 3 seconds is set in the app, then I send an on command on HomeKit, will the plugin/HomeKit know to show that the SwitchBot is off after the 3 seconds are over?

And as general point, can the plugin determine the state of the SwitchBot through the API?

benjaminbogdanovic commented 4 years ago

Then there's also the press/down/up methods, so it looks like I could add a set mode option to the plugin. However, I'm not sure if this is a limitation of node-switchbot or the SwitchBot API, but node-switchbot does not support press timers.

That's good to know. If I have the time, and once I get head around why it is still showing as a switch accessory after I changed all the relevant references to a lock accessory, I might look at implementing this so that the settings are not split between the app and the plugin.

zizi4n5 commented 4 years ago

Sorry, I phrased that question poorly. For example, if the press mode with a timer for 3 seconds is set in the app, then I send an on command on HomeKit, will the plugin/HomeKit know to show that the SwitchBot is off after the 3 seconds are over?

You can set the press timer, but I think the status is the same that in-press state and post-press state of the SwitchBot.

And as general point, can the plugin determine the state of the SwitchBot through the API?

In the case of node-switchbot, the state of the SwitchBot is You can get it as Advertisement Data. However, I don't know how to use it in detail because I don't use it. https://github.com/futomi/node-switchbot#advertisement-data

benjaminbogdanovic commented 4 years ago

Sorry, I phrased that question poorly. For example, if the press mode with a timer for 3 seconds is set in the app, then I send an on command on HomeKit, will the plugin/HomeKit know to show that the SwitchBot is off after the 3 seconds are over?

You can set the press timer, but I think the status is the same that in-press state and post-press state of the SwitchBot.

Does that mean that it will show as on in the Home app, even though the timer has turned it off?

I guess I will find out soon when my delivery arrives!

benjaminbogdanovic commented 4 years ago

I have received my SwitchBot and it behaves as discussed. Would a timeout/timer for the state that is shown in HomeKit (on or off) be difficult to implement, so it can be matched with the timer in the app?

I have achieved this by using the ping feature, but setting an IP that will always be unreachable.

zizi4n5 commented 4 years ago

There will be some unnecessary pings, but I think it's a no problem that way.