How to deal with capabilities with overlapping commands?

An opinion question. I am creating a custom driver for Ring cameras (which I will share when I'm done). Ring cameras have both a light so I implemented Light and a siren so I want to implement Alarm. The problem is they both use on() and off(). I see it pretty rare that I would want to do both at once. How have people handled implementing capabilities in the same driver that have overlapping commands so that things can be done individually? Is there a best practice?

Yes, the best practice is to use a Composite Driver (i.e. Parent/Child). The Parent Driver could implement the Switch Capability for normal On/Off functionality. The Parent would also programatically create a Child device that implements the Alarm Capability. This will allow Apps to reference the Ring Camera as two separate devices.

You could also have a single Parent Device that only creates child devices (one Switch for each Ring Camera, and one Alarm for each Ring Camera (if needed)). The Parent would handle ALL communications to the Ring system, and all of the cameras would be created as child devices.

My HubDuino Arduino integration follows this design, allowing users to have many "Switch", "Contact Sensor", "Motion Sensor", etc... devices all attached to a single Arduino or ESP8266. Feel free to take a look at that groovy code to get some ideas if you like.

1 Like

Following, hoping this will support my driveway Ring Floodlight...

@mjn.other I have it working to turn the lights on/off and detect motion. Also have battery reporting for spotlights. However motion detection relies on an alexa routine. Ring hasn't opened up their api... I'll post more details this evening

1 Like

The Alarm capability doesn't support the on command, it only supports siren, strobe, both, and off.

I personally think off should always stop whatever the device is doing so I've never seen that overlap as an issue.

2 Likes

So here is what I have so far - I created an app that you give your ring username/password. It will login via the api and detect your devices. I can only test what I have so it correctly detected my ring pro, floodlights, and solar spotlights. It will create one of three virtual devices for each - a Ring Doorbell, a Ring Camera, or a Ring Battery Camera. Doorbells will have a momentary button and motion detector. Cameras have a light and motion detector. Battery cameras have a light, motion detector, and battery. I'm still working on the alarm. There is one other device it creates called a Ring Manager. This is actually a dimmer. It is the only device you need to expose to an Alexa Routine. Basically the app has settings where you say "if the dimmer level is 3 that means the doorbell is pressed, if it's 4 the walkway camera has detected motion, etc." So alexa sets the dimmer to the right value via the routine. The app polls the api at a configured interval to check battery status and light status. The motion and buttons are handled via the alexa routine. Turning the light on /off is handled via the api. So far it is working great for me. I'm hoping in another week or two or will be in a state that I'm not embarrassed to release it.

2 Likes

@krlaframboise one follow up - the Ring cameras don't have a strobe function, only siren. Is there a way to say strobe isn't supported? It automatically shows up in the command list when I add the Alarm capability

I typically implement the strobe() command to simply call the siren() command in that situation. So, strobe(), siren(), and both() all do the same thing. Seems better than having commands that do nothing.

What @ogiewon said...

Thanks guys, I decided to take a different approach though - I realized, what exactly is strobing? Well it's just turning on and off, so I just did that manually :slight_smile:

@mjn.other and anyone else who cares - I should have a version of the code ready for beta testing this weekend. I have the lights working (though there seems to be a weird glitch I had to work around where sometimes it only stays on for half a second), motion detection working using an Alexa routine, and siren working (though I didn't test siren a ton due to the risk of angering my neighbors). For doorbells it will also report button presses using Alexa. Finally if the camera is battery powered it will report the battery levels. I just need to get some documentation written up and get it in github,

Edit: Oh I also added a custom command called record(). I wanted a way that I could trigger recording (basically a "live view" via the app). I wanted to build something where if my alarm system detects an intruder I want all my cameras to start recording