# eWeLink

The `ewelink` plugin reads smart plugs and switches from an eWeLink cloud account and reports each device's state. It would suit someone who wants power draw or on/off state from Sonoff-style devices next to the rest of their fleet.

It is not currently enabled. `plugins/plugins/index.ts` has its import and registry entry commented out, so the published plugin set does not include it, and adding `ewelink` to the `plugins` array does nothing. The rest of this page describes what the code in `EwelinkPlugin.ts` does.

## Enable it

There is no supported way to enable it today. The file also no longer matches the plugin library. It extends a `MonitoringPlugin` class from `~/lib/MonitoringPlugin`, which now exports only the `createMonitoringPlugin` factory, so restoring the registry line alone will not build. 
As written, the plugin reads its login from environment variables, not from the config file:

```sh
EWELINK_EMAIL=you@example.com
EWELINK_PASSWORD=YOUR_PASSWORD
```

It loads them with `dotenv`, so a `.env` file next to the agent works too. Without both, setup fails.

| Option | Default | What it does |
| --- | --- | --- |
| `EWELINK_EMAIL` | required | eWeLink account email. Environment variable. |
| `EWELINK_PASSWORD` | required | eWeLink account password. Environment variable. |
| `refreshInterval` | `30000` | Milliseconds between polls, read from the `ewelink` config section. |

The `email`, `password`, `region` and `devices` keys shown for `ewelink` in `client.config.json.example` and `client/README.md` are not read by the code.

## What it reports

One payload per device in the account, with the device's `deviceid` as its unique id. The payload is the device object from the `ewelink-api` package as returned by `getDevices()`, including `name` and `params`.

The plugin polls once at setup and then every `refreshInterval`.

## When it alerts

The server's `ewelink` rule sets warning, "One or more EWeLink devices are offline", when `devices[]` in the payload contains an entry with `status` of `offline`.

The plugin sends one device per payload with no `devices` array, so this rule never matches what the plugin sends. As written, eWeLink devices never alert.

## On the dashboard

The card is labelled "eWeLink" and named after the device.

- The badge shows `on` or `off` from `params.switches[0].switch`.
- POWER shows `params.power` in watts.
- VOLTAGE shows `params.voltage` in volts.

Neither metric is colored. The card's overall color comes from the status the server stored, which as noted is always online. An eWeLink service with no report for 300 seconds shows OFFLINE.

## Requirements

- An eWeLink account and outbound internet access to the eWeLink cloud.
