Walt HelpOpen a case
Getting startedUsing WaltConnectionsAccount and privacy

Send a Shelly sensor straight to Walt

Connections

A plugged-in Shelly from the Plus, Pro, Gen3 or Gen4 lines can run a small script of its own. With the one below, a Shelly smart plug sends its power use straight to Walt every five minutes. You don't need a hub, a home server or the forwarder.

It works on Shellies that measure power and stay plugged in, such as the Plug US Gen4, Plus Plug or a 1PM. Battery Shellies, such as the H&T and the Flood leak sensor, sleep between readings and can't run scripts: use the forwarder for those (see Battery Shellies). Older Gen1 devices can't run scripts and the forwarder can't read them, so they need a hub (see Connect your own hub with a webhook).

1. Make a token in Walt

  1. Go to House → Sensors and tap + Connect sensors.
  2. Pick Webhook, name it after the plug, such as "Dryer plug", and tap Make webhook token.
  3. Copy the token straight away. Walt shows it once.

Give each plug its own token. Then if you unplug one for good, you can revoke just that one.

2. Add the script to the Shelly

  1. Open the Shelly's own page in a browser by typing its address, such as http://192.168.1.42. The Shelly app shows the address under the device's settings.
  2. Open Scripts and tap Create script. Name it "Walt".
  3. Paste the script below, and put your token between the quotes on the first line. Walt uses the name you gave the plug in the Shelly app, and picks up a rename on the next post. A plug with no name shows up under its Shelly id until you name it.
  4. Tap Save, then Start. Turn on Run on startup so the script comes back after a power cut.
walt-shelly.js
let TOKEN = "walt_hook_paste_your_token_here";
let EVERY_MINUTES = 5;

let URL = "https://heywalt.app/api/ingest/readings";
let ID = Shelly.getDeviceInfo().id;

// The plug's own name from the Shelly app: the output's name, else the device's.
function plugName() {
  let out = Shelly.getComponentConfig("switch:0");
  if (out && out.name) return out.name;
  let sys = Shelly.getComponentConfig("sys");
  return sys && sys.device && sys.device.name ? sys.device.name : null;
}

function send() {
  let s = Shelly.getComponentStatus("switch:0");
  if (!s || !s.aenergy) return;
  let body = {
    meters: [{
      id: ID + "/switch:0",
      name: plugName(),
      utility: "electric",
      unit: "Wh",
      total: s.aenergy.total,
      rate: Math.max(0, s.apower || 0)
    }]
  };
  Shelly.call("HTTP.Request", {
    method: "POST",
    url: URL,
    headers: { "Authorization": "Bearer " + TOKEN, "Content-Type": "application/json" },
    body: JSON.stringify(body),
    timeout: 15
  }, function (res, code, msg) {
    if (code !== 0) print("Walt: could not post, " + msg);
    else if (res.code !== 202) print("Walt answered " + res.code + ": " + res.body);
  });
}

send();
Timer.set(EVERY_MINUTES * 60 * 1000, true, send);

3. Check it arrived

Within a minute the plug shows on House → Energy as a meter. Tap it there to link it to the thing it measures, such as the dryer.

If nothing shows up, open the script on the Shelly and read the log under the editor:

  • Walt answered 401 means the token is wrong or was revoked. Make a new one and paste it in.
  • Walt answered 400 means the post was refused. The message after it says which field.
  • could not post means the Shelly can't reach the internet. Check its Wi-Fi.

Battery Shellies

Battery Shellies sleep between readings, so they can't run a script. If they already send to an MQTT broker on your home network, run Walt's forwarder beside the broker instead. It listens to your Plus, Pro, Gen3 and Gen4 Shellies and posts what it heard to Walt every five minutes.

  1. Turn on MQTT in each Shelly's settings and point it at your broker.
  2. Make a webhook token as in step 1, named for the forwarder, such as "Shelly forwarder".
  3. On a computer at home that stays on and has Docker, run this with your broker's address and your token:
Shell
docker run -d --restart unless-stopped \
  -e MQTT_URL=mqtt://192.168.1.10:1883 \
  -e WALT_TOKEN=walt_hook_paste_your_token_here \
  -e STATE_FILE=/data/state.json \
  -v walt-forwarder:/data \
  ghcr.io/doorgames-io/walt-mqtt-forwarder:latest

If your broker needs a login, add -e MQTT_USERNAME=… and -e MQTT_PASSWORD=… before the last line.

Plugs and meters show on House → Energy within five minutes. Battery sensors show on House → Sensors after up to three hours the first time, because a sleeping sensor can stay quiet that long and the forwarder waits to hear from all of them. After that, a restart lists them straight away.

Good to know

  • The token lives on the Shelly. Anyone who can open the Shelly's page can read it, so set a password on the device under Settings → Authentication. A token can only send readings. It can't read anything back from Walt or change anything in your house.
  • The plug sends its running total, so a missed post loses nothing. The next one fills the gap.
  • Walt only reads the plug. It never switches it on or off.
  • If you also run the Walt forwarder, it reports the plug under the same id, so Walt counts it once. That holds as long as you haven't changed the Shelly's MQTT prefix.