Handles communication with the next generation of Shelly devices
npm install elyeu-shelly-node5Handles communication with the next generation of Shelly devices.
_This branch adds support for the I4 DC version device._
For the first generation of Shelly devices, see node-shellies.
For the source of this branch, see the great work of Alexander Rydén at node-shellies-ng.
* Shelly Plus 1
* Shelly Plus 1 PM
* Shelly Plus 2 PM
* Shelly Plus I4
* Shelly Plus I4 DC 2
* Shelly Plus Plug US
* Shelly Plus H&T 1
* Shelly Pro 1
* Shelly Pro 1 PM
* Shelly Pro 2
* Shelly Pro 2 PM
* Shelly Pro 3
* Shelly Pro 4 PM
1 Support for outbound websockets is a work in progress.
2 Works currently the same way as the original I4.
``typescript
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);ID: ${device.id}
console.log();
// 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.