Ring API
An unofficial, friendly Javascript API for ring doorbells, cameras, etc.
- Happy in node or browsers
- Promised-based
- Glosses over ring's API weirdness
- Hides http polling behind an event-driven interface
Requires a JS runtime that supports ES6 async/await or else traspilation
usage
const RingApi = require( 'ring-api' );
const ringApi = await RingApi( {
email: 'you@example.com',
password: 'password you use on ring.com',
poll: true,
serverRoot: 'http://example.com'
} );
Listening for activity on your ring devices
const logActivity = activity => console.log( 'there is a activity', activity );
ringApi.events.on('activity', logActivity);
The event will be fired on rings and motion detected. To distinguish between then, use the activity.kind
property.
Where the activity object looks like:
{
kind: 'motion',
id: '6500907085284961754',
id_str: '6500907085284961754',
state: 'ringing',
protocol: 'sip',
doorbot_id: 3861978,
doorbot_description: 'Back garden',
device_kind: 'hp_cam_v1',
motion: true,
snapshot_url: '',
expires_in: 175,
now: Date,
optimization_level: 1,
sip_server_ip: '...',
sip_server_port: 15063,
sip_server_tls: true,
sip_session_id: '...',
sip_from: '...',
sip_to: '..',
audio_jitter_buffer_ms: 300,
video_jitter_buffer_ms: 300,
sip_endpoints: null,
sip_token: 'long hex token',
sip_ding_id: '6500907085284961754',
}
Getting a list of devices
ringApi.devices();
Where the promise will resolve to an object like:
{
all: [ ],
doorbells: [ ]
authorizedDoorbells: [],
chimes: [ ],
cameras: [ ] ],
baseStations: []
}
Turning lights on and off
const prompt = require('node-ask').prompt;
async function lightsOnAndOff() {
const devices = await ringApi.devices();
console.log( `turning on all lights` );
await Promise.all( devices.cameras.map( c => c.lightOn() ) );
await prompt( 'all your lights are now on, hit return to turn them off' );
await Promise.all( devices.cameras.map( c => c.lightOff() ) );
console.log( 'they\'re all off again!');
};
lightsOnAndOff();
Getting device history and videos
async function logMyRingHistory() {
const history = await ringApi.history();
const firstVideoUrl = await history[0].videoUrl();
console.log( 'latest video is at', firstVideoUrl );
const allRecentVideos = Promise.all( history.map( h => h.videoUrl() ) );
console.log( 'list of all recent videos:', await allRecentVideos );
};
starting a livestream
So far this only works so far as getting the SIP details of the stream. To get this, can do:
devices.doorbells[0].liveStream();
getting device health
async function printHealth( device ) {
const strength = (await device.health()).latest_signal_strength;
console.log( `${device.description} wifi strength is ${strength}` );
}
const devices = await ringApi.devices();
printHealth( devices.doorbells[0] );
printHealth( devices.chimes[0] );
printHealth( devices.cameras[0] );
debugging
To get extended debugging info, since ring-api uses https://www.npmjs.com/package/debug you
can set the DEBUG
environment variable to ring-api
(or add ring-api to it if it is already set)
For example, to run the example script from bash with debugging you might do:
env DEBUG="$DEBUG ring-api" ./examples/example-script
Thanks to