Smart Home & API
MIYO (Cube series) can be integrated into a smart home, either via ready-made integrations or directly through the Cube API. HTTP, WebSocket, and MQTT provide access to the Cube on your own network. Remote access via the app is independent of this.
Integrations
Ready-made integrations are available for popular platforms. You can find setup instructions and more information on the respective pages:
- Home Assistant – Integration for local home automation; Sensor and valve status, as well as manual irrigation
- openHAB Binding – Binding for openHAB; sensors, valves, and manual irrigation
- Homey App – App for Homey (local Homey installations); sensors, valves, and manual irrigation
- IFTTT Service – Connect to hundreds of other services and devices via applets (triggers and actions)
API
All three methods use the same interface. A request consists of a two-part name (Area.Method), a number id, and optional parameters. The response is a JSON object with the same id, the status success or error, and either the requested data or an error message. You can find the available requests and their parameters in the MIYO API documentation.
HTTP and WebSocket are unencrypted. Therefore, use them only within your home network. An API key grants permission to control irrigation. Treat it like a password.
HTTP
The Cube accepts HTTP connections on port 80 and can be reached on the same network via mDNS at miyocube (_http._tcp). You can reach it from another subnet via its IP address. Requests are sent to http://<Cube-IP>/api/…. Arguments are passed as part of the URL, for example apiKey. The Cube does not process a JSON body. The response is returned as JSON.
Almost every call requires the apiKey parameter. The Cube provides a new key while in pairing mode. Pressing the button on the Cube starts this mode for 15 minutes. During this time, a key is issued once, after which pairing mode ends. The exact procedure is described in the API documentation. Without a valid key, the Cube responds with an error and HTTP status 403. A restricted key allows you to query the state and control irrigation. Setup, deletion, and system calls are not possible with a restricted key.
WebSocket
The same interface is also available as a WebSocket on port 3810: ws://<Cube-IP>:3810, protocol version 13. The service is also named miyocube (_ws._tcp) via mDNS.
Each call is sent as a JSON object in a text message:
id– number that the Cube returns in its responsemethod– call name in the formatArea.Method, with exactly these two partsapiKey– the key at the top level of the messageparams– parameters, if the call requires any
The response is returned over the same connection. In addition, the Cube sends state changes to all connected clients. These messages contain the notification field and the id -1. They are not sent retroactively: after connecting, you will only receive state changes that occur from that point on.
The key is checked by the Cube with every message. The port is accessible to every device on the network. Calls fail without a valid key. The same rules apply to apiKey as for HTTP, including restricted keys.
MQTT
With MQTT, the Cube itself is the client and connects to an MQTT broker. You enter the broker address and, optionally, a username and password. You can also choose whether to encrypt the connection using SSL/TLS. If no port is specified in the address, 1883 is used, or 8883 with TLS. Leaving the address blank disables the MQTT client. If the connection drops, the Cube automatically reconnects and publishes its current state again.
The Cube's client ID is its UUID. Your program uses its own client ID. If a client connects with the same ID, the broker disconnects the existing connection using that ID.
Publish a call as JSON to this topic:
miyo/<Cube-UUID>/api/<Bereich>/<Methode>
The message has the form {"id": 1, "params": { … }}. The slash in the topic corresponds to the dot in the call name. The Cube UUID and device and circuit IDs are specified in the topic without curly braces. In HTTP responses, the same IDs are often shown as {…}.
The MQTT call contains id and params. The Cube executes the call with full privileges. Therefore, protect the broker accordingly: set a username and password, and allow only trusted clients to publish to miyo/<Cube-UUID>/api/#. Outside a purely local network, the connection should be encrypted with TLS.
Responses are published to miyo/<Cube-UUID>/response and contain the same id 1. They are not retained. So subscribe to the topic before sending a call. Multiple programs can share this response topic and distinguish their responses by the id. If a message contains invalid JSON, the Cube responds on this topic with an error.
The Cube stores the current state of devices and circuits persistently on the following topics:
miyo/<Cube-UUID>/device/<Geräte-ID>miyo/<Cube-UUID>/circuit/<Bereichs-ID>
A new subscriber receives the retained message immediately after subscribing. If a device or circuit is removed, the Cube deletes the corresponding retained message.
Changes are also published as non-retained messages. The topic name uses slashes, for example miyo/<Cube-UUID>/Device/stateChanged. After connecting, the retained device and circuit topics provide the current state you can rely on.
When connecting, the Cube also publishes the MQTT discovery information for Home Assistant. Setup for this integration is described on the Home Assistant page.
