ENERGY · smart-plug

Smart Plug

Remote power with basic energy readings.

5 capabilitiesREST + secure WebSocketProduction schema
OVERVIEW

Built from capabilities, not assumptions.

Smart Plug is a canonical HomeAutoPro energy template. The same production capability schema drives validation, controls, reported state, telemetry, scenes and automations. Undeclared keys are rejected.

WRITABLE CAPABILITIES

Controls

ControlTypeRange / valuesDescription
PowerpowerbooleanON / OFFWritable through validated owner commands and automations.
DEVICE → HOMEAUTOPRO

Feedback / state

Every connected device also reports online state and last-seen time. Applied values remain distinct from requested values until the device acknowledges them.

Powerpower

boolean. Report the value actually applied after each command.

Voltagevoltage

number · V. Read-only device feedback.

Currentcurrent

number · A. Read-only device feedback.

Powerpower_w

number · W. Read-only device feedback.

Energyenergy_kwh

number · kWh. Read-only device feedback.

TIME-SERIES VALUES

Telemetry

Voltagevoltage

Validated number in V, 0–300. Publish in a telemetry message.

Currentcurrent

Validated number in A, 0–100. Publish in a telemetry message.

Powerpower_w

Validated number in W, 0–10000. Publish in a telemetry message.

Energyenergy_kwh

Validated number in kWh, 0–100000. Publish in a telemetry message.

CAPABILITY-AWARE WORKFLOWS

Automations

Triggers

State/telemetry changes for power, voltage, current, power_w, energy_kwh, plus online and offline events.

Actions

Validated commands for power. Applied state is reported as ACK.

ACTUAL PRODUCTION PROTOCOL

Payloads and acknowledgement

Dashboard/APIHomeAutoProDeviceApplied-state ACK

Authenticate

{"type":"auth","device_secret":"YOUR_DEVICE_SECRET"}

Command

{
  "event": "command",
  "state": {
    "power": true
  }
}

State ACK

{
  "state": {
    "power": true
  },
  "type": "state"
}

Telemetry

{
  "telemetry": {
    "current": 50.0,
    "energy_kwh": 50000.0,
    "power_w": 5000.0,
    "voltage": 150.0
  },
  "type": "telemetry"
}
CAPABILITY-GENERATED EXAMPLES

Sample code

Choose one platform. All examples use the production protocol and placeholders; no stored secret is retrieved.

C++ · ESP8266
#include <ESP8266WiFi.h>
#include <ArduinoJson.h>
#include <WebSocketsClient.h>

const char* DEVICE_CODE = "YOUR_DEVICE_ID";
const char* DEVICE_SECRET = "YOUR_DEVICE_SECRET";
WebSocketsClient socket;

// Handle only: power
// Connect: socket.beginSSL("api.homeautopro.in", 443, path);
// First message: {"type":"auth","device_secret":DEVICE_SECRET}
// After a command, publish {"type":"state","state":applied}.
SAFE DIAGNOSTICS

Troubleshooting

401 authentication

Use the current Device Secret locally. Rotate it in Device Details if it was lost.

422 validation

Compare every key, type and range with the capability schema above.

No command ACK

Publish the value actually applied after handling event=command.