Skip to main content

Commands

EMS-ESP has a command API which can be used to read and write values to EMS device and call specific commands.

There are 3 methods commands can be invoked:

  • via the Console using Telnet or Serial
  • via HTTP using RESTful API calls
  • via MQTT via topics and their payloads

Definitions​

Important Definitions
  • <device> is the short-name. It can be either:
    • a EMS Device and supported devices include: boiler thermostat mixer heatpump solar gateway switch controller pump generic heatsource ventilation

      • the EMS-ESP system itself identified as system
      • the Dallas temperature sensors as temperaturesensor
      • any custom Analog sensors as analogsensor
      • any EMS telegram custom entities as custom
    • <command> is the name of either

      • a generic command, or
      • an EMS device entity also referred to as an <entity>. See the Supported Devices page for the complete list
    • <id> is an optional identifier and has different meanings depending on the context

    • <data> is used to represent the value to read or write. It can be either a single value as any type (integer, float, string or boolean) or a JSON object string containing multiple key/values pairs as:

      • "cmd" is the <command>. The key "cmd" may also be substituted for "entity".
      • "value" is the value and can be either a text string in quotes, an integer, float of boolean. "data" is an alias that can also be used instead for the key.
      • "hc", "wwc" and "id" are all are used to represent a value or in the context of an EMS Device a heating or warm water circuit.
    • A boolean value can be represented in many forms:

      • as a True value, "TRUE", "yes", true, "true", "on", 1
      • as a False value, "FALSE", "no", false, "false", "off", 0
    • The API key authenticates HTTP requests. Create one in the WebUI's Settings->Security->API Keys page: a "Read" key can read values and run Commands that guests may run, a "Read and Write" key can also change values and settings. Send it in the HTTP header as "Authorization: Bearer {API_KEY}". From 3.10.0 every call to /api needs it, including reads.

Console​

  • Commands can be executed using the call command
  • You need to be admin to use the call command. First su and enter the password
  • For a list of all available commands you can use show commands
  • The syntax is call <device> <command> [data] [id]
  • For a complete list of commands use call <device> commands

For more information on how to use the Telnet Console see the Console section.

HTTP​

Things to note:

  • The REST API follows the OpenAPI Specification
  • The URL path always starts with http://<hostname>/api/
  • <hostname> is either an IP address or the mDNS name, which default is ems-esp.local
  • Every call needs an API key, created in the WebUI's Security->API Keys, in the HTTP header like "Authorization: Bearer {API_KEY}". Calls without one get HTTP 401. Changing values or settings needs a "Read and Write" key
  • To look at a value in a browser, open its address, for example http://ems-esp.local/api/boiler/curflowtemp, and sign in with your EMS-ESP username and password when the browser asks. This only reads values, also for admins. Tools that only support a username and password can use an API key as the password, with any username, for example http://user:[email protected]/api/boiler. The key keeps its rights there, except in a browser, where it only reads
  • With HTTP POST commands an HTTP body may be required. This can be in the form of either plain text or as a JSON object <data>, the Content-Type-header has to be set to application/json in both cases.
  • HTTPS with self-signed certificates are not yet supported
  • For a complete list of commands use http://<hostname>/api/<device>/commands
  • using ems-esp v2-api style GET commands is still supported (http://<hostname>/api?device=<device>&id=<id>&cmd=<cmd>)

Reading and Writing EMS Device information​

The URL path is http://<hostname>/api/<device>/

endpointHTTP methodactionauthentication required?post body
infoGEToutputs current EMS device information in verboseno
valuesGEToutputs current EMS device information in short formatno
(empty)GETsame as values aboveno
commandsGETlists the available command entities to callno
entitiesGETlists all enabled entitiesno
{entity}GEToutputs details of a specific entity, for readingno
{entity}/{hc}GETsame as the read command above but for a specific heating circuitno
{entity}POSTupdates a entity value, for writingyes<data>
{entity}/{hc}POSTsame as the write command above but for a specific heating circuityes<data>

Examples:

URLpost bodyaction
http://ems-esp.local/api/thermostat/seltemp22sets the selected room temperature of the master thermostat on heating circuit 1
http://ems-esp.local/api/thermostat/hc2/seltemp{"data":22}sets the selected room temperature of the master thermostat on heating circuit 2
http://ems-esp.local/api/thermostat/mode'auto'sets the thermostat mode to auto for heating circuit 1
http://ems-esp.local/api/thermostat{"cmd":"mode", "data":"auto"}sets the thermostat mode to auto for heating circuit 1
http://ems-esp.local/api/thermostat{"cmd":"seltemp", "data":23, "hc":3}sets the selected room temperature to 23 degrees for heating circuit 3
http://ems-esp.local/api/thermostat/hc2{"cmd":"seltemp", "data":20.5}sets the selected room temperature to 20.5 degrees for heating circuit 2
http://ems-esp.local/api{"device":"thermostat", "cmd":"seltemp", "data":23, "hc":3}sets the selected room temperature of the master thermostat on heating circuit 3

Fetching and writing to custom entities​

The URL path is http://<hostname>/api/custom/

endpointHTTP methodactionauthentication required?post body
blank or infoGEToutputs all custom entities and their valuesno
commandsGETlists the available custom entity commandsno
<name>GEToutputs all characteristics for a specific custom entityno
<name>/<attribute>GEToutputs an attribute of a specific custom entityno
<name>POSTupdates a custom entity value, for writingyes<data>

Fetching Temperature Sensor information​

The URL path is http://<hostname>/api/temperaturesensor/

endpointHTTP methodactionauthentication required?post body
blankGEToutputs connected Dallas temperature sensor names and readingsno
infoGEToutputs all details on the connected Dallas temperature sensorsno
<name>GEToutputs all characteristics for a specific temperature sensorsno
<name>/valueGEToutputs the value of a specific temperature sensorno

Controlling the Analog Sensors​

The URL path is http://<hostname>/api/analogsensor/

endpointHTTP methodactionauthentication required?post body
blankGEToutputs analog sensors and their readingsno
infoGEToutputs all details on the connected analog sensorsno
<name>GEToutputs all characteristics for a specific analog sensorsno
commandsGETlists the available system commandsno
setvaluePOSTset value/offset of counter or output pin, +/- sign corrects valueyes{"value":<val>, "id":<gpio>}
<name>POSTset value/offset of counter or output pin, +/- sign corrects valueyes{"value":<val>}

System Commands​

The URL path is http://<hostname>/api/system/<endpoint>

endpointHTTP methodactionauthentication required?post body
info valuesor blankGEToutputs current system informationno
fetchGETforces at refresh of all device valuesno
restartGETrestarts EMS-ESPyes
formatGETfactory reset's EMS-ESPyes
commandsGETlists the available system commandsno
sendPOSTsend telegram to the EMS busyes"XX XX...XX"
messagePOSTsend a message to the log and MQTT. The message can also a logic command as used in the Scheduleryes".." or '{"value":"system/settings/locale"}'
publishPOSTMQTT publish all values, and optional HA-configuration or specific for a deviceno[ha] | [device]
watchPOSTwatch incoming telegramsno<on |off | raw | <type-id(hex)>
valuesGEToutputs all values in short formatno
readGETqueries a specific EMS device and a typeIDyes<deviceID> <type ID> [offset] [length]
responseGEToutputs the last response from EMS-ESPno
entitiesGETlists all enabled entitiesno
sendmailPOSTsend an emailyes{"to":"<email>", "subject":"<subject>", "body":"<body>"}
txpausePOSTpause/resume the transmission of the EMS busyes<bool>
ledPOSTLED patternyes[color]:[pattern]
mqtt/enabledGETenable/disable MQTTyes<bool>
ap/enabledGETenable/disable Access Pointyes<bool>
ntp/enabledGETenable/disable NTPyes<bool>
syslog/enabledGETenable/disable Syslogyes<bool>
settings/analogenabledGETenable/disable analog sensoryes<bool>
settings/hideledGETenable/disable LEDyes<bool>
settings/showeralertGETenable/disable shower alertyes<bool>
settings/showertimerGETenable/disable shower timeryes<bool>

Examples​

tip

In these examples the URL is http://ems-esp.local/api/ but adjust to your actual hostname. Also change the API key to your own as described in the Definitions section.

...via the command line​

# GETs need an API key too, a "Read" key is enough
% curl http://ems-esp.local/api/thermostat/seltemp -H 'Authorization: Bearer emsesp_...'

# POSTs (with -d) that change a value need a "Read and Write" key
% curl http://ems-esp.local/api/thermostat/seltemp \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer emsesp_...' \
-d '{ "value" : 22.5 }'

# GET to restart EMS-ESP, needs a "Read and Write" key
curl http://ems-esp.local/api/system/restart -H 'Authorization: Bearer emsesp_...'

# This example will get the system info, via a GET request
curl -X GET -H "Authorization: Bearer ${emsesp_token}" ${emsesp_url}/api/system/info

# This example will execute a read command on product ID 8 and type ID 1
curl -X POST \
-H "Authorization: Bearer ${emsesp_token}" \
-H "Content-Type: application/json" \
-d '{"data":"8 1"}' \
${emsesp_url}/api/system/read

# This example will export all values to a json file, including custom entities, sensors and schedules
curl -X POST \
-H "Authorization: Bearer ${emsesp_token}" \
-H "Content-Type: application/json" \
-d '{"action":"export", "param":"allvalues"}' \
${emsesp_url}/rest/action

...using a Python script​

import requests
import json

url = "http://ems-esp.local/api/thermostat/temp"
token = "emsesp_..." # a "Read and Write" API key
body = json.dumps({ "value": 22.5 })
headers = { 'Content-Type': 'application/json', 'Authorization': 'Bearer ' + token }

response = requests.post(url, headers=headers, data=body, verify=False)

print(response.json())

MQTT​

MQTT uses the same format as the API, but with a few differences. For the topic the <hostname> is replaced with the MQTT Base name as defined in the Settings (default is ems-esp). The <device> follows the same names as listed at the top of this page. For example ems-esp/thermostat/<entity> or ems-esp/custom/<name>.

The MQTT payload is the same as the <data> as described above and used in the API, and can be a JSON object or a string.

What MQTT may do is set in the MQTT settings with "Commands received over MQTT": "Off, only read values", "Change values and run Commands" (the default) or "Everything, also system commands". system/... commands, such as system/send or system/restart, need "Everything". A factory reset (system/format) and erasing the crash dump (system/coredump) are never accepted over MQTT. Publish commands without the retain flag; retained commands are ignored.

Examples:

topicpayloadaction
ems-esp/system/sendXX XX...XXsend raw ems-command (needs "Everything, also system commands")
ems-esp/thermostat/seltempfetches the seltemp entity values and publishes it in the topic ems-esp/response
ems-esp/thermostat/seltemp23change the selected setpoint temperature to 23 degrees on the master thermostat on hc1
ems-esp/thermostat/modeautosets the thermostat mode to auto for hc1
ems-esp/thermostat{"cmd":"mode","value":"heat","id":1}sets the thermostat mode to heat for hc1
ems-esp/custom/myCustomEntity7sets the value of the EMS-ESP Custom Entity named myCustomEntity to 7

Publishing Commands​

EMS-ESP will MQTT 'subscribe' to specific topics depending on the EMS devices attached. For example boiler, thermostat etc.

Commands can be sent to EMS-ESP via these MQTT topics using the payload format:

{"cmd":"<cmd>", "data":<data>, "id":<n>}

where

  • cmd is one of the commands listed in the Commands and must be enclosed in quotes as a String. The key entity may also be used instead of cmd.
  • data (or value) holds the value for the command, and can be either a String or numeric value.
  • id is used as an generic indicator. hc, wwc, ahs and hs are other suppoerted aliases. For example with hc it is used to indicated a specific Heating Circuit. A numeric value or String can be both used.

Some more examples:

topicpayloadaction
ems-esp/boiler{"cmd":"heatingactivated", "data":"on"}turn on heatingactivated in boiler
ems-esp/boiler/heatingactivated{"data":"on"}turn on DHW disinfecting in boiler (equivalent to command above)
ems-esp/boiler{"cmd":"dhw.disinfecting", "data":"on"}turn on DHW disinfecting in boiler

You can check the log in Status - System Log if the command was accepted by EMS-ESP.

The first command in the table above was valid and thus accepted:
Topic:ems-esp/boiler Command/payload: {"cmd":"heatingactivated", "data":"on"}

[command] Called command boiler/heatingactivated (heating activated) with value on

And the following bogus command is not accepted:
Topic:ems-esp/boiler Command/payload: {"cmd":"heatingactivated", "data":"5000"}

[command] Command failed: no values in boiler
[mqtt] MQTT command failed with error no values in boiler (Error)
note

You can easily test the MQTT commands with MQTT Explorer. Just connect to the MQTT broker and publish the payload to the topic.

With Home Assistant, Thermostat commands can also be sent to control individual heating circuits via sending a mode string or temperature number to a topic thermostat_hc<n>.

Depending on mqtt-settings there are also direct subscriptions for each value like boiler/wwtemp, thermostat/hc1/daytemp, etc. Thermostats which supports only a single heating circuits will subscribe to /thermostat/daytemp.

You can also use MQTT to send a specific read request and the telegram response will be returned in a topic called response. For example sending the payload {"cmd":"send", "data":"0B 88 19 19 02"} to ems-esp/system will result in a topic response being published with the data {"src":"08","dest":"0B","type":"19","offset":"19","data":"7D 00","value":32000}.