Skip to content

Device commands

With commands you read and control a device from your own program. This page applies to devices with a serial number that starts with a number or with e, for example 14:3 or e12:57.

Way When you use it What you need
HTTP API The device is connected to the cloud An API key
MCP From an AI assistant An API key
Local network Your computer and the device are on the same network The Allow LAN commands setting
Device network The device has no WiFi or internet The Device key (D/K) from the label

Send the command to device_command.php:

Parameter Value
serialno The serial number
command The command
Terminal window
curl -X POST https://api.hamsystems.eu/device_command.php \
-H "Authorization: Bearer-API YOUR_API_KEY" \
--data-urlencode "serialno=e12:57" \
--data-urlencode "command=STAT"

The example shows some fields of the reply:

{
"messages": [],
"response": [0, [{ "serialno": "e12:57", "uptime": 863483, "version": "1.1.20" }, ""]]
}
  • response[1][0] is the data of the command.
  • response[1][1] is the error. It is empty if the command succeeded.
  • If response is null, the device did not reply. Check its connection.
NAME arg1,arg2
  • Write the name in upper case.
  • Put one space after the name.
  • Separate the arguments with a comma, with no spaces.
  • Put text in double quotes.
  • Write numbers with no quotes.

A command with no arguments does not accept arguments. The command STAT 1 gives the error BAD FORMAT.

Error Meaning
Access denied You do not have the permission for this command on this device.
OVERFLOW An argument is too large.
BAD FORMAT The arguments are wrong. Check the quotes and the commas.
BAD COMMAND The device does not have this command.
OUT OF BOUNDS The output number is out of range.
NOT FOUND The setting key does not exist on this device.
FAILED The device did not complete the command.
NOT SUPPORTED The device does not have this function.

Each command needs a minimum permission level on the device.

Command What it does Minimum level
READ Reads the state View
RREAD Reads the readings directly from the device Manage
WRITE Sets an output Control
WRITEM Sets many outputs Control
STAT Reads the device details Manage
RTIMED Reads the schedules View
TIMED Sets a schedule Manage
RSET Reads the settings View
SET Changes a setting Manage
MODBUSR Reads from a Modbus device View
MODBUSW Writes to a Modbus device Manage
UPGRADE Starts a firmware update Manage
READ
[{ "rssi": -47, "R": { "T": 2138, "GI": 1 }, "ALR": 0, "serialno": "e12:57", "disconnected": false }, ""]
Field Content
R The readings, as raw values. In the example, T: 2138 means 21.38 °C. See the family definitions in the HTTP API.
O The output values. The position in the list is the output number.
rssi The signal strength
ALR The alarm state

The value 2147483648 means that the reading is missing.

RREAD
[{ "RR": { "E": 0, "E2": 0, "P_": 2147483648, "GI": 1 }, "RO": [[0, 0, 0]], "ALR": 0 }, ""]
Field Content
RR The readings of the device
RO One row for each output: [value, timeout, last on value]

Use RREAD when READ shows no readings. This can occur on a device that has not connected to the cloud.

READ and RREAD read the sensors again. On a slow sensor, two commands in a row can give different values.

WRITE index,value
Argument Value
index The output number, from 0. It is the position in output_names in the family definitions.
value From 0 to 255. On an on/off output, 0 is off and any other value is on.

The command WRITE 0,255 turns on output 0. The reply has the field O with all outputs.

WRITEM value0,value1

The first value goes to output 0, the second value to output 1, and so on. An output with no value does not change. The device ignores the values after the last output.

The command WRITEM 255,0 turns on output 0 and turns off output 1. The reply has the field O with all outputs.

STAT
Field Content
serialno The serial number
uptime The seconds since the last start
version The firmware version
ip, mac The IP address and the MAC address
rssi The signal strength
TIMED index,start,interval,duration,output_index,output_value
Argument Value
index The position in the schedule list, from 0
start The start, in UNIX seconds (UTC)
interval The repeat in seconds. 0 means no repeat.
duration The duration in seconds. After the duration, the output gets the value 0. 0 means no end.
output_index The output number. A negative value changes the slot of the energy counter.
output_value The output value. With a negative output_index, it is the slot of the counter. After the duration, the slot gets the value 0.

The command TIMED 0,1793750400,86400,3600,0,255 turns on output 0 every 24 hours, for 1 hour.

To repeat on specific days, interval is a day mask shifted left by 25 bits. Bit 0 is Monday and bit 6 is Sunday.

Days interval
Monday only 33554432
Monday to Friday 1040187392

To delete a schedule, send TIMED 0,0,0,0,0,0.

RTIMED has no arguments. The field T of the reply has one row for each position: [start, interval, duration, output_index, output_value]. The number of rows is the number of positions on the device.

The schedules in the app are the same schedules. A change by command also shows in the app.

RSET has no arguments. The reply shows the settings of the device.

The first letter of the key shows the type of the value:

The key starts with Value Example
i A number with no quotes SET "iST",1
s Text in quotes SET "sID","Fridge 1"

The keys of each family are in the settings field of the family definitions.

Use these keys on a device with no cloud connection.

Command What it does
SET "TIME",1793703945 Sets the time, in UNIX seconds (UTC)
SET "W_P","ssid","password" Sets the WiFi network

In the example, the counter is the energy E, in Watt seconds.

Command What it does
SET "aE",1000 Adds 1000, only if the device did not get a value from the server
SET "AE",1000 Adds 1000 in all cases
SET "CE",1000 Sets the value to 1000

These commands operate only on devices with a Modbus connection. See Modbus devices. Other devices reply NOT SUPPORTED.

MODBUSR slave,function,address,count
MODBUSW slave,function,address,"value"
Argument Value
slave The slave address
function For MODBUSR: 3 holding registers, 4 input registers, 1 coils, 2 discrete inputs. For MODBUSW: 6 single register, 5 single coil, 16 many registers.
address The register address, in decimal
count The number of registers to read. The maximum is 100.
value The bytes in hex. Each register has 4 hex digits. For a coil, ff00 is on and 0000 is off.

The command MODBUSR 1,3,100,2 reads 2 registers from address 100 on slave 1:

[{ "val": "00fa0001" }, ""]

The command MODBUSW 1,6,100,"00ff" writes 00ff to register 100 on slave 1.

If the Modbus device does not reply correctly, the error is FAILED.

UPGRADE

The device downloads and installs the firmware that the server offers for it. The device must be connected to the cloud. The reply shows the current version:

[{ "version": "1.1.20" }, ""]

By default the device does not accept commands from the local network.

  1. Turn on the Allow LAN commands setting in the device settings.

  2. Copy the Authorization token for LAN access. The app shows it only one time.

  3. Find the IP address of the device with the STAT command or in the router.

  4. Send the command:

    Terminal window
    curl -H "Authorization: Bearer YOUR_LAN_TOKEN" "http://192.168.1.50/?c=READ"

Devices get an address only from DHCP. For a fixed address, see the router settings.

On devices with a serial number that starts with e:

  • The token is mandatory. With no correct token, the reply is HTTP 403.
  • After 10 failures, the device replies HTTP 429 for 5 minutes.
  • Turn on the setting from the app. The command SET "iALC",1 does not make a token, and the device rejects the requests.

For the token and the safety measures, see Security.

This way operates with no WiFi and no internet. It does not need the LAN token. It needs the Device key (D/K) from the label.

  1. Connect to the device network. Follow the steps in the hotspot method.

  2. In a browser, open the address with the command:

    http://192.168.4.1/?c=RSET

Encode the command for a URL:

Character Encoding Example
Space + ?c=WRITE+0,255
Quotes %22 ?c=SET+%22TIME%22,1793703945

On devices with a serial number that starts with e, the encoded command has a limit of 127 characters.

The command SET "W_P" ends setup mode. The device connects to the new WiFi network.

Chat with support