jhulbertpmn / node-shellies-ng-ul

Handles communication with the next generation of Shelly devices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

node-shellies-ng

npm-version

Fork of the original from alexryd to modify the (for now) Pro 2 and Pro 2PM model numbers to use the UL suffix

Handles communication with the next generation of Shelly devices.

For the first generation, see node-shellies.

Supported devices

1 Support for outbound websockets is a work in progress.

Basic usage example

import {
  Device,
  DeviceId,
  MdnsDeviceDiscoverer,
  Shellies,
  ShellyPlus1,
} from 'shellies-ng';

const shellies = new Shellies();

// handle discovered devices
shellies.on('add', async (device: Device) => {
  console.log(`${device.modelName} discovered`);
  console.log(`ID: ${device.id}`);

  // use instanceof to determine the device model
  if (device instanceof ShellyPlus1) {
    const plus1 = device as ShellyPlus1;

    // toggle the switch
    await plus1.switch0.toggle();
  }
});

// handle asynchronous errors
shellies.on('error', (deviceId: DeviceId, error: Error) => {
  console.error('An error occured:', error.message);
});

// create an mDNS device discoverer
const discoverer = new MdnsDeviceDiscoverer();
// register it
shellies.registerDiscoverer(discoverer);
// start discovering devices
discoverer.start();

See homebridge-shelly-ng for a real-world example.

About

Handles communication with the next generation of Shelly devices

License:GNU General Public License v3.0


Languages

Language:TypeScript 99.9%Language:JavaScript 0.1%