anthonywebb / homebridge-cbus

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

Ability to control group address by monitoring state change #85

Open mattangelofdeth opened 6 years ago

mattangelofdeth commented 6 years ago

Thanks again for such an AMAZING product

I have a group address which would be awesome if it could be controlled by homebridge by monitoring state change

Currently I have a garage door (sitting on channel 1) and a garage door status group address on channel 2 (example addresses only)

Using a AUX module and a magnetic sensor we can monitor the status of the garage door via channel 2, HOWEVER, as you cant control the door using channel 2 (only monitor the status), Im unable to get any data into homekit to show the state of the door (open or shut)

As I've ditched wiser now, I'm hoping for a solution to my problem!

Being able to read a state change would be very helpful Any help would be greatly appreciated!

MtSamsonite commented 6 years ago

If you have a logic module you can do this in CBUS. 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)

Logic below. 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

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.