If connecting using the cloud proxy (https://server.myio.com.br), each request should contain those two headers to identify the target central
x-access-token: TOKEN central-id: CENTRAL_UUID
Request a token from the auth endpoint. This token will be used on all requests to the central
$ curl -d http://localhost:8080/v2/slaves
curl --location --request POST 'https://server.myio.com.br/users/auth' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "user@myio.com.br",
"password": "123456"
}'
{
"user": {
"UUID": "c7e480a5-8ecd-4c17-b8d7-b3c256446bb2",
"name": "Test User",
"email": "user@myio.com.br",
"cpf": "11111111111",
"role": "default",
"centrals": []
},
"token": "eyJhbGciOiJIUzI1NiJ9.eyJVVUlEIjoiYzdlNDgwYTUtOGVjZC00YzE3LWI4ZDctYjNjMjU2NDQ2YmIyIiwibmFtZSI6IlRlc3QgdXNlciIsImVtYWlsIjoidXNlckBteWlvLmNvbS5iciIsImNwZiI6IjExMTExMTExMTExIiwicm9sZSI6ImRlZmF1bHQiLCJjZW50cmFscyI6W10sImlhdCI6MTU4MjcyMjY5Nn0.i676OT42a3RJaxWdv35RwBCZg4pgNqtogxUOVCIiMHg",
"valid_until": 1614345096333
}
Each registered product in a central is called a Slave.
Types
| Type | Description |
|---|---|
| outlet | Myio Switch, can be used on Light Switches or Outlets, has two inputs and two outputs and is able to measure up to 10A of current on each input |
| infrared | Myio Remote, can be used to remote control infrared or 433MHz radio devices |
| light_switch | Myio LightSwitch, dimmer-enabled light switch with physical buttons |
| three_phase_sensor | Myio SU, three-phasic sensor measuring realtime energy using external CT Sensors |
Slave
| Property | Description |
|---|---|
| id | Primary key ID of the Slave |
| type | Type of the Slave, can be one of: "outlet", "light_switch", "infrared", "three_phase_sensor" |
| addr_low | Slave address, used internally to uniquely identify it on the mesh network |
| addr_high | Slave address, used internally to uniquely identify it on the mesh network |
| name | Slave name as defined by the User |
| code | Slave code |
| clamp_type | If this Slave has an external CT Sensor measuring the consumption, its reference will be passed to this attribute (0 - 50A, 1 - 100A, 2 - 400A, 3 - 1000A, 4 - 2000A) |
| aggregate | Indicates whether this slave consumption is considered on the total consumption aggregation |
| version | HW Version, "SemVersioned" |
| last_consumption | Indicates the last consumption read from the device |
| status | Indicates the quality of the connection to the device, can be one of: "waiting", "online", "offline", "bad" |
| channels | List of Channels |
| devices | If the slave is a infrared, it will have a list of user-created Devices |
Channel
| Property | Description |
|---|---|
| id | Primary key ID of the Channel |
| type | Can be one of: "plug", "dimmer", "lamp", "remote", "pulse_up", "pulse_down" |
| channel | Number of the channel, will be used to identify the channel on the Slave on Websocket messages |
| name | Name of the Channel, as defined by the User |
| value | Current Slave value, can range from 0 to 100 |
| scene_id | Only valid when type is remote, used to trigger a Scene when the Channel is physically activated |
Device
| Property | Description |
|---|---|
| id | Primary key ID of the Channel |
| type | Can be one of: ir (Infrared), rf (433 MHz Radio-Frequency) |
| name | Name of the Device, as defined by the User |
| output | Output of the device, can be one of: "external", "internal", "both" |
Lists all slaves in the database
$ curl http://localhost:8080/v2/slaves
[
{
"id": 8,
"type": "outlet",
"addr_low": 3,
"addr_high": 1,
"name": "TV Outlet",
"code": null,
"clamp_type": null,
"aggregate": true,
"version": "2.0.0",
"last_consumption": 352,
"status": "offline",
"channels": [{
"id": 20,
"type": "plug",
"channel": 0,
"name": "TV",
"value": 0,
"scene_id": null
}, {
"id": 21,
"type": "plug",
"channel": 1,
"name": "TV Box",
"value": 0,
"scene_id": null
}]
}, {
"id": 6,
"type": "infrared",
"addr_low": 8,
"addr_high": 248,
"name": "Test IR",
"code": "2357",
"aggregate": true,
"version": "2.0.0",
"battery": null,
"temperature": null,
"status": "online",
"devices": [{
"id": 20,
"type": "ir",
"category": "tv",
"name": "TV",
"output": "both"
}, {
"id": 21,
"type": "ir",
"category": "ac",
"name": "A/C",
"output": "both"
}]
}
]
Connect to the Myio C WebSocket API using the Local API at: http://hubot.local:3000/websocket
After the connection has been upgraded to websocket, you will start receiving messages.
{
"message_type": "auth_req"
}
Upon connection, you will receive on the WebSocket connection an auth_req message. Every time this message is received, you should answer with an auth request containing a provided token (signed with the Central's private key) and central_id
The API will respond with either auth_success or auth_fail if the token is invalid.
{
"message_type": "auth",
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVVUlEIjoiMTIzIiwicm9sZSI6ImFkbWluIiwibmFtZSI6Ik15aW8gTG9jYWwiLCJ1c2VyX2lkIjoiMSIsImxvY2FsT25seSI6dHJ1ZSwiaWF0IjoxNTY5MTc0NTA5fQ.u0xNvONiiNQsFjE84VgW1ou85SDeVmRihivmz5lLhfA",
"central_id": "8753cddb-9bdf-44cf-a22c-f77c431d0767"
}
{
"message_type": "auth_success"
}
{
"message_type": "auth_fail"
}
After a connection is successfully established with the Myio C and you are authenticated, you will be able to activate Channels from Slaves using its identifying channel number and slave_id.
Since this is a Websocket connection, there is no immediate response as you would have in a HTTP POST request. To know if the request was successfuly executed, you must wait a response of type channel_update and verify if the channel value you sent a message to changed its value.
If the communication to the Slave failed, you will receive a timeout message with the slave_id
{
'type': 'slave',
'id': 21,
'command': 'light_control',
'channel': 0,
'value': 100
}
{
"message_type": "channel_update",
"id": 21,
"channels": [{
"value": 0,
"id": 0
}, {
"value": 0,
"id": 1
}, {
"value": 100,
"id": 2
}]
}
{
"message_type": "timeout",
"id": 21
}
A Device is a User-created entity that represents a Infrared or 433MHz physical device remote control
A Device has one or more buttons that are created by the User on the Myio Webapp.
A Button is a recorded infrared or 433MHz command.
Lists all Buttons on a Device
Button
| Property | Description |
|---|---|
| id | Primary key ID of the Button |
| type | Ununsed. Will be used to identify the Button type so we can answer properly to GHome/Alexa/Home.app Thermostat |
| indexes | Indexes of the button on the webapp grid |
| color | Button color on the webapp grid, can be 0 — white or 1 — purple |
| rfir_command_id | Foreign Key of the CommandId, will be used to send this button's action to be activated. |
| single_send | SingleSend mode is used to guarantee this message will be sent. This introduces a delay (min: 300ms, max: 3s) on the message because we wait until the product answers a "check" command before sending the actual command to the slave. Set this to false if this is a user action as the user can physically hear the command being activated (and repeat if needed.) |
$ curl http://localhost:8080/v2/devices/20/remotes
[{
"id": 20,
"name": "A/C Remote",
"rfir_buttons": [{
"id": 1,
"name": "On",
"indexes": "7",
"color": 0,
"rfir_command_id": 244,
"type": null,
"single_send": false
}, {
"id": 2,
"name": "Off",
"indexes": "3",
"color": 0,
"rfir_command_id": 243,
"type": null,
"single_send": false
}]
}]
After a connection is successfully established with the Myio C, you will be able to activate Channels from Slaves using its identifying channel number and slave_id.
Since this is a Websocket connection, there is no immediate response as you would have in a HTTP POST request. To know if the request was successfuly executed, you must wait a response of type channel_update and verify if the channel value you sent a message to changed its value.
If the communication to the Slave failed, you will receive a timeout message with the slave_id
| Property | Description |
|---|---|
| id | slave_id of the command we want to tansmit |
| command | Command to be sent to this Slave process, in this case, transmit |
| rfir_command_id | Command Id of the Command to be sent |
| type | Type of the message to be sent, in this case, the message will be sent to a infrared slave |
{
'type': 'slave',
'id': 20,
'command': 'transmit',
'rfir_command_id': 244
}
{
"transmit_duration": 175,
"message_type": "transmit_success",
"id": 20
}
{
"message_type": "timeout",
"id": 20
}