satrik / homebridge-bslamp2

Homebridge plugin to control Mi Bedside Lamps 2
MIT License
5 stars 0 forks source link

Issue when turning on or off with wireless switch #1

Closed kikher closed 2 years ago

kikher commented 2 years ago

Hello, I don't know if it's a bug or a problem in my configuration. After several problems with my bedside lamp 2 with homkit, I have decided to try your plugin. Apparently everything works fine, maybe a little slow when interacting with the lamp. The problem I have is that when I turn on the lamp with a wireless switch, I have to click twice, to turn it off or to turn it on, if it is on and I press the switch in the hombidge log, another one appears just like the previous state. and if I press again, at that moment it turns off and the same thing happens in the opposite case.

Could you tell me if there is any way to solve it?

Thank you very much for your work.

Captura de pantalla 2022-02-16 a las 12 29 06
satrik commented 2 years ago

Hi, sounds like your switch isn't configured properly.

What switch is it and how have you integrated it into homebridge/homekit? Is there any automation/scene which's toggles the state for the switch?

kikher commented 2 years ago

I use several and have tried it on all of them. I have several philips dimmers and also several ikea on/off dimmers. They are integrated into home kit through deconz and the homebride Hue plugin. With other lights it works normally, it only has that behavior with the lamp and the plugin, since if I add it with homekit with the code it works normally Unknown-1 Unknown .

satrik commented 2 years ago

Again, is there any automation/scene which's toggles the state for the switch? What is the "logic" after you've pressed the switch?

And does the lamp work normally if you control it via homekit or do you need to click there also twice?

The plugin just do what homebridge says, and the log clearly shows that false/true was received twice each time. So the issue can only be within the switch or the automation afterwards.

kikher commented 2 years ago

Sorry, I forgot to answer that question. I have it configured with the shortcuts option, in this way: -If the lamp is inactive. -turn on the lamp. -otherwise. -Turn off the lamp. -end. The funny thing is that I have more things like this and it only happens here. but it doesn't matter because I can change the settings. I was only commenting on it in case that issue had been documented in other cases.

I just tried with siri and it works fine and from the home app too, so I understand that the problem comes when it interacts with the shortcut.

satrik commented 2 years ago

Hmm, I had something similar with another device and I could solve it with this workaround.

For the bslamps I have also another automation which toggles on/off with a simple scene. Scenes automatically toggles the lamp without the need to check the power state :)

kikher commented 2 years ago

I've just been doing tests with what it says in that article. when I call the shortcut the first time, the lamp turns on but in homekit it is not notified on. I give it a second time and it already notifies in homekit on. I give it a third time and it turns off but homekit does not notify it off. and I give it the fourth time and it is already notified in homekit as if it is turned off.

It's curious. Could it be that some configuration data of the lamp is not correct in homebridge? something that I did not do well when doing bslamp pair?

kikher commented 2 years ago

Hello again, I have unlinked and relinked and the following happens.

match and then give error. Is it normal or is there a way to fix it?

bslamp pair 192.168.XXX.XXX XXX-XX-XXX
Search Device
Found MiBedsideLamp2-1031
Start pairing
MiBedsideLamp2-1031 successfully paired!

Paste the following into your homebridge config
'name' is what you see in homebridge/homekit and can be changed
===========COPY START===========
{
    "accessory": "MiBedsideLamp2",
    "name": "Mi Bedside Lamp 2",
    "id": "76:XX:XX:XX:XX:XX”,
    "address": "192.168.XXX.XXX”,
    "port": 80,
    "pairingData": {
        "AccessoryPairingID": "3XXXXXXXXXXXXXXX4",
        "AccessoryLTPK": "35XXXXXXXXXXXXXXXXXX3",
        "iOSDevicePairingID": "3XXXXXXXXXXXXXXXXXXXXXXX4",
        "iOSDeviceLTSK": "bXXXXXXXXX8d",
        "iOSDeviceLTPK": "55XXXXXXXXXXXXd"
    }
}
============COPY END============
MiBedsideLamp2-1031 pairing failed
===========ERROR START===========
Error: EACCES: permission denied, open '/usr/local/lib/node_modules/homebridge-bslamp2/bslamp-192-168-XXX-XXX’
    at Object.openSync (node:fs:585:3)
    at Object.writeFileSync (node:fs:2155:35)
    at IPDiscovery.<anonymous> (/usr/local/lib/node_modules/homebridge-bslamp2/bslamp.js:67:28)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) {
  errno: -13,
  syscall: 'open',
  code: 'EACCES',
  path: '/usr/local/lib/node_modules/homebridge-bslamp2/bslamp-192-168-XXX-XXX’
}
============ERROR END============
satrik commented 2 years ago

Error: EACCES: permission denied, open '/usr/local/lib/node_modules/... there is something really broken with your user permissions. Is homebridge running under the user homebridge? If yes, you can try something like

chown -R homebridge: /usr/local/lib/node_modules/homebridge-bslamp2/

Also try to delete all files with names like bslamp-192-168-XXX-XXX inside /usr/local/lib/node_modules/homebridge-bslamp2/. Afterwards completely reset the lamp and set it up new. But the permissions of your homebridge user needs fixed before.

satrik commented 2 years ago

Oh wait the message comes after the pairing and not inside homebridge... the problem is that your user (pi or whatever) don't have write rights in this directory. Quick fix - try the pairing again with sudo. The written file is just needed to unpair the lamp again.

kikher commented 2 years ago

Cool! I'm going to try it with sudo. Tomorrow I will give you an answer that in my country it is already too late. My homebridge setup is via the homebridge raspberry pi image (https://github.com/homebridge/homebridge-raspbian-image) I have been trying to find what user it uses but i cant figure it out.
I think that with sudo the problem will be solved, however tomorrow I will confirm.
Thank you very much for your attention.

kikher commented 2 years ago

hello,

The installation issue has been solved with the sudo command at the beginning.

The part of shortcuts in the switch, after giving it many turns I have managed to solve it in a very rudimentary way. Adding in front of the shortcut 2 actions to get the status of the accessory and at the end another two. 4 in all. It's the only way for honekit to get the actual state of the lamp.

If I find another solution I will send it to you. Thank you very much for your help.

satrik commented 2 years ago

Still weird, but automations in homekit just aren't the best 🤷🏼‍♂️ You should try it with a scene, for me it works very good.