Meross smart plug local control over HTTP
README.md

meross #

Control Meross smart plugs over their local HTTP API, without the cloud.

Overview #

Meross smart plugs are normally driven through the vendor's cloud and app, which means an account, an internet connection, and a round trip through a remote server to switch a plug a few metres away. The plugs also answer a signed HTTP API on the local network. meross speaks that API directly, one plug at an IP address, with no account and no internet connection. Each request header carries a messageId, a timestamp and a sign field, the hex MD5 of the message id, the key and the timestamp concatenated. A plug that was never paired with the cloud accepts an empty key, so the signature only matches the format the plug expects: it authenticates nobody, and anyone on the local network can switch the plug.

It covers:

  • power control: on, off, toggle and reboot;
  • live electricity readings (voltage, current, power) and historical consumption;
  • countdown timers and automation triggers;
  • the LED's Do Not Disturb mode and the Wi-Fi signal;
  • the abilities a plug advertises, and attempts to put a Matter plug into pairing mode;
  • scanning a range of addresses for plugs.

The package also installs a meross command-line tool with one command per operation.

Installation #

Install with opam:

$ opam install meross

If opam cannot find the package, it may not yet be released in the public opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install meross

Usage #

let run ~http ~sw ip =
  (match Meross.info ~http ~sw ip with
   | Ok info -> Fmt.pr "%a@." Meross.pp_info info
   | Error (`Msg e) -> Fmt.epr "Error: %s@." e);
  let _ = Meross.turn_on ~http ~sw ip in
  let _ = Meross.turn_off ~http ~sw ip in
  match Meross.electricity ~http ~sw ip with
  | Ok e -> Fmt.pr "Power: %.1f W@." e.Meross.Electricity.power
  | Error _ -> ()

Modules #

  • Meross.Protocol is the HTTP protocol and its message signing.
  • Meross.Device reads device information and switches power.
  • Meross.Electricity and Meross.Consumption read live power and historical energy use.
  • Meross.Timers and Meross.Triggers manage countdown timers and automation rules.
  • Meross.Dnd switches the LED's Do Not Disturb mode.
  • Meross.Runtime reads the Wi-Fi signal and other runtime figures.
  • Meross.Abilities lists the namespaces a plug supports.
  • Meross.Commissioning tries the Meross namespaces that may open a Matter commissioning window, or unbind a plug from its current fabric.
  • Meross.Duration formats durations for humans.

Supported Devices #

The library has been tested with the MSS310 (smart plug with energy monitor) and the MSS315 (the same with Matter). Other Meross plugs with the local HTTP API may work, but none has been tested.

Licence #

ISC License. See LICENSE.md for details.