anthonywebb / homebridge-cbus

CBus plugin for homebridge
MIT License
35 stars 20 forks source link

Bell Press working only once #63

Closed MtSamsonite closed 7 years ago

MtSamsonite commented 7 years ago

Firstly a huge thank you to the developers for this plugin.

I have added around 40 C-Bus devices to homebridge and all are working well with the exception of my garage door. The garage door is using a low voltage relay and requires a bell press. I have configured the garage door in config.json as a switch with a duration of 1 second.

When homebridge is fired up I see the current state of all my devices. When I press "on" in home app for the garage door switch I see the cbus message for on and then a subsequent off after 1 second appear on the homebridge console. The garage door immediately opens/closes depending on prior position.

The issue I have is it only works the once (first time) when I try to turn it on again, I see no messages relayed to cbus. There is literally no output logged to the homebridge console on any subsequent presses.

The group address I am using in the config.json is the relay address.

Does this function only work with an actual c-bus switch type or should this be working in my situation where I am using a switch function to control a low voltage relay?

Not sure if I need to change something in C-Bus or my config.json or if this an error within the homebridge plugin.

Any advice is appreciated.

Mike

DarylMc commented 7 years ago

@MtSamsonite If it is the CBus 8 channel extra low voltage relay it has a fairly slow response time. Do you have the garage door working off a regular CBus key input?

MtSamsonite commented 7 years ago

@DarylMc

It is the 8 channel extra low voltage relay. I do appreciate it may be slow, but in this instance their is not even a command being sent from homebridge on the second or any subsequent activation via homekit.

I do have a Cbus key input also configured, and plan on trying to configure the accessory to use the key input in place of the relay as I understand you are likely suggesting. Only issue is the accessory is in another application group, hopefully simply adding the application group parameter to this accessory in config.json to specify an alternative application group is all that is required.

I will give this a go tonight and report back.

Thanks for your input

Mike

DarylMc commented 7 years ago

I just tried bell press and it does seem to have a problem. On the first press it works fine. One the second press no on command is seen on the CBus network and button does not time out. Another press sees command "off" on cbus network. For me next on command works fine. Also if phone goes to sleep between on presses or home app is closed it seems to work correctly.

MtSamsonite commented 7 years ago

@DarylMc

Thank you for testing and confirming the fault. Sometimes with these types of projects you can never be sure if its something wrong with your set-up or a fault in the software. Greatly appreciate you replicating the error.

Mike

DarylMc commented 7 years ago

@anthonywebb @simonhac Hello I had a look at the switch accessory.js file but could not quite understand how it all works. Just to try help I will mention as best I can what is happening at least for me.

Open Home app and bell press function works fine first time. It activates the relay, indicates on, times out at one second and indicates off on phone as expected. Next press it indicates on but there is no command seen on Homebridge or CGate and it doesn't time out. Next press the phone indicates off and the command is seen on Homebridge and CGate. Next press it works correctly again.

If the app is closed and reopened the Homebridge requests the status of the CBus network. It works fine every time for the first use in that case.

MtSamsonite commented 7 years ago

@DarylMc Thanks Daryl for investigating a little further. I have noticed you contribute significantly to a lot of the C-bus forums.

Its actually a friends house I was assisting with I don't have C-Bus myself though I am considering it given I have now had to learn toolkit and piced to assist my friend.

I no longer require the bell press as we connected a push switch on the garage door rails and connected it to a aux input module so we could tell when it was closed. I then used another group address as the switch with some logic that checks the door status and toggles the relay to close/open the door. This logic runs on my friends PAC module. This enables us to simply use a on/off switch in homebridge which accurately represents the door state at all times (eg: on=open and off=closed). (the logic will retry toggling the door up to 4 times as it reverses direction in the situation it was interrupted with a uhf key or button connected directly to the garage door. If it fails it puts the switch back to prior position so the state remains accurate)

I will leave the issue open for the developers as they may wish to investigate for other users. If this is not the correct protocol and I should be closing the issue if it no longer concerns me, please let me know.

Mike

DarylMc commented 7 years ago

@MtSamsonite Nice work. That sounds impressive and a much better setup. Did you run through recovery settings and check response from mains power cycle?

Leave the issue open until we hear from @simonhac or @anthonywebb

MtSamsonite commented 7 years ago

@DarylMc

To be totally honest we haven't I think we should be ok but will check. Appreciate the advice.

I think the logic should correct any state discrepancies on first scan but you have me questioning that now as I consider the mix of scenarios. It seems I'm not finished with it yet.

I will leave the issue open as advised

Mike

DarylMc commented 7 years ago

Probably most importantly check the recovery settings for the relay though it probably is alright. It wouldn't hurt to test it all in a power recovery scenario. I'd like to see the logic you made because it sounds like you put a bit of thought into it and I am about to help someone set up a garage door.

MtSamsonite commented 7 years ago

@DarylMc Daryl, I did it on my friends pc via teamviewer so don't have the code here, I have asked him to email me the code so I can share with you but essentially the garage door setup is as follows (written in pseudo code as I dont have the correct syntax in front of me)

Set up garage door relay to group "garage relay" Set up garage door push switch to aux input module - bistable switch =on/off activates group "garage door status" Setup group "Dummy Switch" ( I assigned this to a spare relay port, c-bus should also work with an virtual group address, but I had read homebridge-cbus needs to be attached to a real c-bus unit, not sure how accurate this is as I haven't tested yet using a group not attached to an actual unit).

Code something like this

RetryCount: integer once dummy switch = on begin RetryCount :=1 while garage door status = off and RetryCount <5 begin SetLightingState garage relay = on delay(1) Set:LightingState garage relay = off delay(20) (time for door to fully open or close with some margin for motor slowing over time) end end once dummy switch = off (repeat block of code above with off/on states inverted) ... ... once garage door status = on if dummy switch = off setlighting state dummy switch = on once garage door status = off if dummy switch = on setlighting state dummy switch = off Thinking about power recovery as you had advised you need to ensure the aux input (push switch) is always driven by the state of the contact at powerup eg: open/close on the input module = on/off initial state. Then for the state of the dummy switch we need to add one line to the initialisation section of the logic so it only runs once when the logic unit is started up (not as in a once statement that is evaluated on every scan) that code would simply be setLightingState dummy switch = getLightingState garage door status. After that it is the dummy switch group you can expose in homebridge or even put on a cbus switch so the on/of status (led) on the switch always reflects the state of the door (open/closed). Noting that should several bell presses be required (rarely - only if door is interrupted/blocked) then it could take up to 80 seconds for the switch to revert to prior state to show it did not work as expected. Wiring in a beam sensor or the like you could add logic to check blockages etc. If you added a second push/reed/limit switch to the garage door for when it is fully open you could enhance the logic a little more as you could distinguish fully open and fully closed. In our case we only have a push switch for closed so open could mean just partially open (but we cant tell). Having said that the closed position is the one we want to be certain about from a security perspective so suits our application. If I could get your email Ill get the code and email if you like. I wouldn't mind corresponding with you on related matters with C-Bus as I am considering purchasing and have also done a couple of Cgate/homebrige raspberry pi setups as I noticed you are also offering. Mike
MtSamsonite commented 7 years ago

@DarylMc Seems my line breaks for sample code above did not work when commenting. Hope you can make sense of the above.

Mike

DarylMc commented 7 years ago

@MtSamsonite Send me a PM on CBus forum and I will give you all my contact details. I'm thinking of going to new Wiser product release this week if I can find out some more details when and where.

rbhr commented 7 years ago

@DarylMc @MtSamsonite Thanks for your work on this guys. How good is this homebridge-cbus now! I see you mentioned Wiser. I happened to be looking through npmjs yesterday and saw this: paulw11/homebridge-wiser Tried it out - it works but limited device types etc at the moment. I'm sticking with this addon as it is far superior and I've used and still use a bunch of Anthony's great code over the years.

DarylMc commented 7 years ago

@rbhr I think Homebridge CBus is pretty good too. A real credit to the folks who made it.

PhilPearson commented 7 years ago

I've figured out what the issue is and submitted a potential fix. Hopefully will get merged soon.

DarylMc commented 7 years ago

I'm just trying to give it a go now

DarylMc commented 7 years ago

@PhilPearson That's great it worked and no other problems noted at this stage. I wish I understood a bit more about it. On my pi3 sudo nano /usr/lib/node_modules/homebridge-cbus/accessories/switch-accessory.js added the line 71 from your fix and rebooted.

Thanks very much.

DarylMc commented 7 years ago

@MtSamsonite I just found while making a Homebridge-CBus pi3 image for someone a bit of a problem. I made an image for someone else's Home. They had a different IP address for the CNI so it wasn't actually connected to my CNI when I booted up the pi. I was able to add all the accessories on my phone and operate them on the phone interface. It occurred to me that if the CNI goes down due to power failure or whatever reason the Home app will not reflect status correctly. I tested it here with my own project and found that to be the case. You can see that is a bad thing especially for remote access control. Just wanted you and everyone else to be aware.

DarylMc commented 7 years ago

@MtSamsonite @anthonywebb @simonhac I just made a new image and noticed this is fixed now. Well done. I think the issue can be closed.

MtSamsonite commented 7 years ago

@anthonywebb @simonhac @DarylMc

Thank you for the update. Closing this issue now.