SkillAgentSearch skills...

Rachio

Node.js client for Rachio Smart Sprinkler controller

Install / Use

/learn @boatmeme/Rachio
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

rachio

Node.js client for the Rachio Smart Sprinkler controller

npm version Build Status codecov Beerpay


Requirements


Install

npm install rachio

Usage

const RachioClient = require('rachio');
const client = new RachioClient('[YOUR-API-TOKEN]');

API

Conventions & Hints

  • All calls are in the context of the api token used to instantiate the client
  • All functions return native Promises unless otherwise noted
  • All resource objects implement .toPlainObject() and .toJson() functions that can aid in application / development / debugging.
  • Don't instantiate the Resource classes directly. Always get an instance from the RachioClient or returned from a method on another Resource instance.
  • There are often multiple ways to accomplish the same tasks in this library. For instance, the RachioClient provides entry points to every resource class provided you know the ids, but as you're learning and exploring the API, it might help to consider a relational approach, i.e., use the RachioClient to get Devices to get Zones, etc.

Classes


RachioClient

This is the entry point for all of your interaction with the Rachio API. Most programs should start by getting an instance of the client using your Rachio Api Key.

const RachioClient = require('rachio');
const client = new RachioClient('YOUR-API-KEY');

// ... Do something useful

All subsequent code examples will presume you have an instance of RachioClient assigned to the variable client in the current application scope.

Methods

getDevices ( )

returns
  • a Promise to return an Array of Device objects
Use Case
  • Get a list of all Rachio devices associated with the API token
Example
code
client.getDevices()
  .then(devices =>
    devices.forEach(d =>
      console.log(`${d.name} : ${d.model} : ${d.id}`)));
output
Rachio-Garage : 8ZR2ULW : 2a5e7d3c-c140-4e2e-91a1-a212a518adc5
Rachio-Backyard : 8ZR2ULW : 8de4dbf6-7a52-43b0-9c18-7d074b868f67

getDevice ( device_id )

parameters
  • a String representing a device id
returns
  • a Promise to return a Device object
Use Case
  • Gets a device so that its properties can be inspected and actions can be performed upon it.
Example
code
const deviceId = '2a5e7d3c-c140-4e2e-91a1-a212a518adc5';

client.getDevice(deviceId)
  .then(device =>
    console.log(`${device.name} : ${device.model} : ${device.id}`));
output
Rachio-Garage : 8ZR2ULW : 2a5e7d3c-c140-4e2e-91a1-a212a518adc5

Other Methods

As mentioned earlier, the RachioClient provides direct access to every resource class represented in the public API. More detail on how these work will be covered in the documentation for the individual resources

getPersonInfo()

Returns information about the currently authenticated user

getDeviceEvents(deviceId, startTime, endTime, filters)

Retrieves a list of events for the given device id

getDeviceCurrentConditions(deviceId, units)

The CurrentConditions as reported by your Rachio's preferred PWS

getDeviceForecast(deviceId, startTime, endTime, units)

The forecasted conditions reported between the start and end dates

getDeviceForecastToday(deviceId, units)

Today's Forecast for the device

getDeviceForecastTomorrow(deviceId, units)

Tomorrow's Forecast for the device

getZonesByDevice(deviceId)

Get all Zone objects for the specified device

getZone(zoneId)

Gets the Zone specified by the zoneId

multiZone()

Gets a new instance of MultiZone for operations across multiple zones

getScheduleRule(scheduleRuleId)

Gets the ScheduleRule for the given id

getFlexScheduleRule(flexScheduleRuleId)

Gets the FlexScheduleRule for the given id

Device

getZones ( )

returns
  • a Promise to return an Array of Zone objects
Use Case
  • Get a list of all zones associated with the Device
Example
code
const deviceId = '2a5e7d3c-c140-4e2e-91a1-a212a518adc5';

client.getDevice(deviceId)
  .then(device => device.getZones())
  .then(zones =>
    zones.forEach(z =>
      console.log(`${z.name} : ${z.zoneNumber} : ${z.enabled} : ${z.id}`)));
output
Zone 1 - Front Door  : 1 : true : ec47f4a6-5771-4d8f-834a-89bc7d889ea4
Zone 2 - Front West : 2 : true : f0e042bd-7ba1-4aba-bede-6d8b16857d3a
Zone 3 - Garage Front : 3 : true : f0e042bd-7ba1-4aba-bede-6d8b16857d3a
Zone 4 - Garage Side : 4 : true : 8de4dbf6-7a52-43b0-9c18-7d074b868f67
Zone 5 - Back Door  : 5 : true : 1f3759cf-8722-4331-8859-aef4e328ce51
Zone 6 - Back Yard : 6 : false : 5bb1b267-7c0d-40a3-b532-d3b4e616c280
Zone 7 : 7 : false : 34c2b94a-2be0-46bd-83af-cc63daa8047c
Zone 8 : 8 : false : d8bd46d1-77ab-4c15-8aa1-b5a529897b37

isWatering ( )

returns
  • A Promise resolving to true if the device is currently watering
  • A Promise resolving to false if the device is not currently watering
Use Case
  • Are any of the zones on the device currently watering?
Example
code
const deviceId = '2a5e7d3c-c140-4e2e-91a1-a212a518adc5';

client.getDevice(deviceId)
  .then(device => device.isWatering())
  .then(isWatering => console.log( isWatering
    ? 'The lunatic is on the grass'
    : 'The lunatic is in my head'));

...Looking outside, I see zone 5 watering...

output
The lunatic is on the grass

stopWater ( )

returns
  • true
Use Case
  • Tell the device to halt any currently running watering activity
Example
code
const deviceId = '2a5e7d3c-c140-4e2e-91a1-a212a518adc5';

client.getDevice(deviceId)
  .then(device => device.stopWater())
  .then(success => console.log(success));
output
true

getActiveZone ( )

returns
  • a Promise to return a Zone object that is currently watering.
  • false if no zone is currently watering
Use Case
  • Get me the zone that is watering right now
Example
code
const deviceId = '2a5e7d3c-c140-4e2e-91a1-a212a518adc5';

client.getDevice(deviceId)
  .then(device => device.getActiveZone())
  .then(activeZone => console.log( activeZone
    ? `The lunatic is in ${activeZone.name}`
    : 'The lunatic is in my head'));

...Looking outside, I see zone 5 watering...

output
The lunatic is in Zone 5 - Back Door

standbyOn ( )

returns
  • a Promise that resolves to a Boolean dependent on the success of the operation
Use Case
  • Tell the device to stand-by and cease running any current or future scheduled activity
Example
code
const deviceId = '2a5e7d3c-c140-4e2e-91a1-a212a518adc5';

client.getDevice(deviceId)
  .then(device => device.standbyOn())
  .then(success => console.log(success));
output
true

standbyOff ( )

returns
  • a Promise that resolves to a Boolean dependent on the success of the operation
Use Case
  • Tell the device to resume all scheduled activity, if it was previously in stand-by mode
Example
code
const deviceId = '2a5e7d3c-c140-4e2e-91a1-a212a518adc5';

client.getDevice(deviceId)
  .then(device => device.standbyOff())
  .then(success => console.log(success));
output
true

rainDelay (durationInSeconds)

parameters
  • durationInSeconds (default = 1 day), a Number representing the number of seconds from now you would like the rain delay to persist
returns
  • a Promise that resolves to a Boolean dependent on the success of the operation
Use Case
  • Set a rain delay for the next 8 hours
Example
code
const deviceId = '2a5e7d3c-c140-4e2e-91a1-a212a518adc5';
const duration = 28800; // 8 hours, in seconds

client.getDevice(deviceId)
  .then(device => device.rainDelay(duration))
  .then(success => console.log(success));
output
true

rainDelayCancel ()

returns
  • a Promise that resolves to a Boolean dependent on the success of the operation
Use Case
  • Cancel a previously set rain delay
Example
code
const deviceId = '2a5e7d3c-c140-4e2e-91a1-a212a518adc5';

client.getDevice(deviceId)
  .then(device => device.rainDelayCancel())
  .then(success => console.log(success));
output
true

Tip

  • This is equivalent to calling Device.rainDelay(0)

getEvents (startTime, endTime, filters)

parameters
  • startTime (optional), a Number representing the Unix time in milliseconds for which you would like to start your event filter
    • Cannot be a number < 28 days from present
  • endTime (optional), a Number representing the Unix time in milliseconds for which you would like to end your event filter
  • filters (optional), an Object whose properties and values you would like to use as a filter for events.
returns
  • a Promise to return an Array of device ```Even
View on GitHub
GitHub Stars8
CategoryDevelopment
Updated1y ago
Forks4

Languages

JavaScript

Security Score

75/100

Audited on Jul 8, 2024

No findings