跳至主要內容

API

Kaipi Lab大约 10 分钟

API

简述

API文档涵盖各种功能,例如检索设备统计信息、屏幕镜像、通知、自定义应用程序、声音播放和氛围灯。您可以通过MQTT和HTTP协议与这些功能进行交互。

状态信息获取

访问各种设备统计信息,如电池、RAM 等:

MQTT TopicHTTP URLDescription
[PREFIX]/statshttp://[IP]/api/statsGeneral device stats (e.g., battery, RAM)
[PREFIX]/stats/effectshttp://[IP]/api/effectsList of all effects
[PREFIX]/stats/transitionshttp://[IP]/api/transitionsList of all transition effects
[PREFIX]/stats/loophttp://[IP]/api/loopList of all apps in the loop

Note: MQTT also broadcasts other data, such as button presses and the current app.

LiveView

Retrieve the current matrix screen as an array of 24bit colors:

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/sendscreenhttp://[IP]/api/screen-GET

When triggering the MQTT API, AWTRIX sends the array to [PREFIX]/screen.

Extras:

  • Access a live view of the screen in your browser: http://[IP]/screen.
  • Options to download a screenshot or generate a GIF from the current display content.
  • http://[IP]/fullscreen gives you a fullscreen liveview. Here you can optionally set the fps as parameter (standard 30)

电源控制

打开或关闭像素时钟:

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/powerhttp://[IP]/api/power{"power": true} or {"power": false}POST

Send the board in deep sleep mode (turns off the matrix as well), good for saving battery life:

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/sleephttp://[IP]/api/sleep{"sleep": X} where X is number of secondsPOST

AWTRIX will only wakeup after time or if you press the middle button once. There is no way to wake up via API.

RTTLT声音播放

播放 MELODIES 文件夹中的 RTTTL 声音:

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/soundhttp://[IP]/api/sound{"sound":"alarm"}POST

播放RTTTL字符串中的RTTTL声音:

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/rtttlhttp://[IP]/api/rtttlrttl stringPOST

氛围灯

将整个像素屏幕设置为自定义的颜色或温度:

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/moodlighthttp://[IP]/api/moodlightSee belowPOST

⚠️ Caution: Using this function results in a higher current draw and heat, especially when all pixels are lit. Ensure you manage brightness values responsibly.

To disable moodlight, send an empty payload.

Example:

{
  "brightness": 170,
  "kelvin": 2300
}

Possible moodlight options:

{"brightness":170,"kelvin":2300}  
or
{"brightness":170,"color":[155,38,182]}  
or
{"brightness":170,"color":"#FF00FF"}  

彩色指示器

Colored indicators serve as small notification signs displayed on specific areas of the screen:

  • Upper right corner: Indicator 1
  • Right side: Indicator 2
  • Lower right corner: Indicator 3
MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/indicator1http://[IP]/api/indicator1{"color":[255,0,0]}POST
[PREFIX]/indicator2http://[IP]/api/indicator2{"color":[0,255,0]}POST
[PREFIX]/indicator3http://[IP]/api/indicator3{"color":[0,255,0]}POST

Color Options:

  • Use an RGB array, e.g., {"color":[255,0,0]}
  • Use HEX color strings, e.g., {"color":"#32a852"}

Hide Indicators:

  • To hide the indicators, send the color black ({"color":[0,0,0]}) or use the shorthand {"color":"0"}. Alternatively, send an empty payload.

Additional Effects:

  • Blinking: To make the indicator blink, add the key "blink" with a value specifying the blinking interval in milliseconds.
  • Fading: To make the indicator fade on and off, add the key "fade" with a value specifying the fade interval in milliseconds.

自定义应用和通知

With AWTRIX Light, you can design custom apps or notifications to showcase your unique text and icons.

Interaction

  • MQTT: Send a JSON object to [PREFIX]/custom/[app], where [app] denotes your app's name (excluding spaces).
  • HTTP API: Incorporate the app name in the query parameter (name=[appname]).
  • Updating: To refresh a custom page, dispatch a modified JSON object to the identical endpoint. The display updates instantly.
  • One-Time Notification: Use the same JSON format. Direct your JSON object to [PREFIX]/notify or http://[IP]/api/notify.
MQTT TopicHTTP URLPayload/BodyQuery ParametersHTTP Method
[PREFIX]/custom/[appname]http://[IP]/api/customJSONname=[appname]POST
[PREFIX]/notifyhttp://[IP]/api/notifyJSON-POST

JSON属性

Below are the properties you can utilize in the JSON object. All keys are optional; only include the properties you require.

KeyTypeDescriptionDefaultCustom AppNotification
textstringThe text to display. Keep in mind the font does not have a fixed size and I uses less space than W. This facts affects when text will start scrollingN/AXX
textCaseintegerChanges the Uppercase setting. 0=global setting, 1=forces uppercase; 2=shows as it sent.0XX
topTextbooleanDraw the text on top.falseXX
textOffsetintegerSets an offset for the x position of a starting text.0XX
centerbooleanCenters a short, non-scrollable text.trueXX
colorstring or array of integersThe text, bar or line color.N/AXX
gradientArray of string or integersColorizes the text in a gradient of two given colorsN/AXX
blinkTextIntegerBlinks the text in an given interval, not compatible with gradient or rainbowN/AXX
fadeTextIntegerFades the text on and off in an given interval, not compatible with gradient or rainbowN/AXX
backgroundstring or array of integersSets a background color.N/AXX
rainbowbooleanFades each letter in the text differently through the entire RGB spectrum.falseXX
iconstringThe icon ID or filename (without extension) to display on the app. You can also send a 8x8 jpg as Base64 StringN/AXX
pushIconinteger0 = Icon doesn't move. 1 = Icon moves with text and will not appear again. 2 = Icon moves with text but appears again when the text starts to scroll again.0XX
repeatintegerSets how many times the text should be scrolled through the matrix before the app ends.-1XX
durationintegerSets how long the app or notification should be displayed.5XX
holdbooleanSet it to true, to hold your notification on top until you press the middle button or dismiss it via HomeAssistant. This key only belongs to notification.falseX
soundstringThe filename of your RTTTL ringtone file placed in the MELODIES folder (without extension).N/AX
rtttlstringAllows to send the RTTTL sound string with the json.N/AX
loopSoundbooleanLoops the sound or rtttl as long as the notification is running.falseX
bararray of integersDraws a bargraph. Without icon maximum 16 values, with icon 11 values.N/AXX
linearray of integersDraws a linechart. Without icon maximum 16 values, with icon 11 values.N/AXX
autoscalebooleanEnables or disables autoscaling for bar and linechart.trueXX
progressintegerShows a progress bar. Value can be 0-100.-1XX
progressCstring or array of integersThe color of the progress bar.-1XX
progressBCstring or array of integersThe color of the progress bar background.-1XX
posintegerDefines the position of your custom page in the loop, starting at 0 for the first position. This will only apply with your first push. This function is experimental.N/AX
drawarray of objectsArray of drawing instructions. Each object represents a drawing command. See the drawing instructions below.XX
lifetimeintegerRemoves the custom app when there is no update after the given time in seconds.0X
lifetimeModeinteger0 = deletes the app, 1 = marks it as staled with a red rectangle around the app0X
stackbooleanDefines if the notification will be stacked. false will immediately replace the current notification.trueX
wakeupbooleanIf the Matrix is off, the notification will wake it up for the time of the notification.falseX
noScrollbooleanDisables the text scrolling.falseXX
clientsarray of stringsAllows forwarding a notification to other awtrix devices. Use the MQTT prefix for MQTT and IP addresses for HTTP.X
scrollSpeedintegerModifies the scroll speed. Enter a percentage value of the original scroll speed.100XX
effectstringShows an effectopen in new window as background.The effect can be removed by sending an empty string for effectXX
effectSettingsjson mapChanges color and speed of the effectopen in new window.XX
savebooleanSaves your custom app into flash and reloads it after boot. Avoid this for custom apps with high update frequencies because the ESP's flash memory has limited write cycles.X

Color: Accepts a hex string or an R,G,B array: "#FFFFFF" or [255,255,0].

示例

Here's a sample JSON to present the text "Hello, AWTRIX Light!" in rainbow colors for a duration of 10 seconds:

{
  "text": "Hello, AWTRIX Light!",
  "rainbow": true,
  "duration": 10
}

绘图说明

!> Please note: Depending on the number of objects, the RAM usage can be very high. This could cause freezes or reboots. It's important to be mindful of the number of objects and the complexity of the drawing instructions to avoid performance issues.

Each drawing instruction is an object with a required command key and an array of values depending on the command:

CommandArray ValuesDescription
dp[x, y, cl]Draw a pixel at position (x, y) with color cl
dl[x0, y0, x1, y1, cl]Draw a line from (x0, y0) to (x1, y1) with color cl
dr[x, y, w, h, cl]Draw a rectangle with top-left corner at (x, y), width w, height h, and color cl
df[x, y, w, h, cl]Draw a filled rectangle with top-left corner at (x, y), width w, height h, and color cl
dc[x, y, r, cl]Draw a circle with center at (x, y), radius r, and color cl
dfc[x, y, r, cl]Draw a filled circle with center at (x, y), radius r, and color cl
dt[x, y, t, cl]Draw text t with top-left corner at (x, y) and color cl
db[x, y, w, h, [bmp]]Draws a RGB888 bitmap array [bmp] with top-left corner at (x, y) and size of (w, h)

示例

Here's an example JSON object to draw a red circle, a blue rectangle, and the text "Hello" in green:

{"draw":[  
 {"dc": [28, 4, 3, "#FF0000"]},  
 {"dr": [20, 4, 4, 4, "#0000FF"]},  
 {"dt": [0, 0, "Hello", "#00FF00"]}  
]}  

着色位置显示文本

AWTRIX Light allows you to present text where specific fragments can be colorized. Use an array of fragments with "t" representing the text fragment and "c" denoting the color's hex value.

{
  "text": [
    {
      "t": "Hello, ",
      "c": "FF0000"
    },
    {
      "t": "world!",
      "c": "00FF00"
    }
  ],
  "repeat": 2
}

同时发送多个自定义页面

AWTRIX Light enables you to dispatch multiple custom pages in a single action. Instead of transmitting one custom page object, you can forward an array of objects.

e.g. MQTT Topic: /custom/test

[
  {"text":"1"},
  {"text":"2"}
]

Handling of Multiple Custom Pages:

  • Suffix Assignment: Internally, the app name receives a suffix, turning it into formats like test0, test1, etc.
  • Updates: You can refresh each app individually or update all of them collectively.
  • Deletion:
    • When erasing apps, AWTRIX doesn't match the exact app name. Instead, it identifies apps that begin with the specified name.
    • To expunge all associated apps, send an empty payload to /custom/test. This action will remove test0, test1, and so on.
    • To eradicate a single app, direct the command to, for instance, /custom/test1.
    • Caution: Deleting just one app may upset the sequence of the remaining apps in the loop, as there's no provision for placeholders to retain order.

删除Custom应用

To remove a custom app, dispatch an empty payload/body to the associated topic or URL.

关闭通知

Easily dismiss a notification that was configured with "hold": true.

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/notify/dismisshttp://[IP]/api/notify/dismissEmpty payload/bodyPOST

切换应用

导航到下一个或上一个应用。

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/nextapphttp://[IP]/api/nextappEmpty payload/bodyPOST
[PREFIX]/previousapphttp://[IP]/api/previousappEmpty payload/bodyPOST

切换到特殊应用

使用其名称直接切换到所需的应用程序。

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/switchhttp://[IP]/api/switch{"name":"time"}POST

Built-in App Names:

  • Time
  • Date
  • Temperature
  • Humidity
  • Battery

For custom apps, employ the name you designated in the topic or HTTP parameter. In MQTT, if [PREFIX]/custom/test is your topic, then test would be the app's name.

更改设置

Adjust various settings related to the app display.

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/settingshttp://[IP]/api/settingsJSONGET/POST

JSON属性

您可以根据自己的喜好调整JSON对象中的每个属性。包括属性是可选的。

KeyTypeDescriptionValue RangeDefault
ATIMEnumberDuration an app is displayed in seconds.Positive integer7
TEFFnumberChoose between app transition effects.0-101
TSPEEDnumberTime taken for the transition to the next app in milliseconds.Positive integer500
TCOLstring/array of intsGlobal text color.RGB array or hex colorN/A
TMODEintegerChanges the time app style.0-41
CHCOLstring/array of intsCalendar header color of the time app.RGB array or hex color#FF0000
CBCOLstring/array of intsCalendar body color of the time app.RGB array or hex color#FFFFFF
CTCOLstring/array of intsCalendar text color in the time app.RGB array or hex color#000000
WDbooleanEnable or disable the weekday display.true/falsetrue
WDCAstring/array of intsActive weekday color.RGB array or hex colorN/A
WDCIstring/array of intsInactive weekday color.RGB array or hex colorN/A
BRInumberMatrix brightness.0-255N/A
ABRIbooleanAutomatic brightness control.true/falseN/A
ATRANSbooleanAutomatic switching to the next app.true/falseN/A
CCORRECTIONarray of intsColor correction for the matrix.RGB arrayN/A
CTEMParray of intsColor temperature for the matrix.RGB arrayN/A
TFORMATstringTime format for the TimeApp.Varies (see documentation)N/A
DFORMATstringDate format for the DateApp.Varies (see documentation)N/A
SOMbooleanStart the week on Monday.true/falsetrue
BLOCKNbooleanBlock physical navigation keys (still sends input to MQTT).true/falsefalse
UPPERCASEbooleanDisplay text in uppercase.true/falsetrue
TIME_COLstring/array of intsText color of the time app. Use 0 for global text color.RGB array or hex colorN/A
DATE_COLstring/array of intsText color of the date app. Use 0 for global text color.RGB array or hex colorN/A
TEMP_COLstring/array of intsText color of the temperature app. Use 0 for global text color.RGB array or hex colorN/A
HUM_COLstring/array of intsText color of the humidity app. Use 0 for global text color.RGB array or hex colorN/A
BAT_COLstring/array of intsText color of the battery app. Use 0 for global text color.RGB array or hex colorN/A
SSPEEDintegerScroll speed modification.Percentage of original scroll speed100
TIMbooleanEnable or disable the native time app (requires reboot).true/falsetrue
DATbooleanEnable or disable the native date app (requires reboot).true/falsetrue
HUMbooleanEnable or disable the native humidity app (requires reboot).true/falsetrue
TEMPbooleanEnable or disable the native temperature app (requires reboot).true/falsetrue
BATbooleanEnable or disable the native battery app (requires reboot).true/falsetrue
MATPbooleanEnable or disable the matrix. Similar to power Endpoint but without the animation.true/falsetrue

Color Values: Can either be an RGB array (e.g., [255,0,0]) or a valid 6-digit hexadecimal color value (e.g., "#FF0000" for red).

过渡效果:

0 - Random
1 - Slide
2 - Dim
3 - Zoom
4 - Rotate
5 - Pixelate
6 - Curtain
7 - Ripple
8 - Blink
9 - Reload
10 - Fade 

时间格式:

%H:%M:%S     13:30:45  
%l:%M:%S     1:30:45  
%H:%M        13:30  
%H %M        13.30 with blinking colon  
%l:%M        1:30  
%l %M        1:30 with blinking colon  
%l:%M %p     1:30 PM  
%l %M %p     1:30 PM with blinking colon  

日期格式:

%d.%m.%y     16.04.22  
%d.%m        16.04  
%y-%m-%d     22-04-16  
%m-%d        04-16  
%m/%d/%y     04/16/22  
%m/%d        04/16  
%d/%m/%y     16/04/22  
%d/%m        16/04  
%m-%d-%y     04-16-22  

固件更新

您可以通过HA中的更新按钮或使用以下命令执行固件更新:

MQTT TopicHTTP URLPayload/BodyHTTP HeaderHTTP Method
[PREFIX]/doupdatehttp://[IP]/api/doupdateJSONempty payload/bodyPOST

重启像素时钟

MQTT TopicHTTP URLPayload/BodyHTTP Method
[PREFIX]/reboothttp://[IP]/api/reboot-POST

格式化像素时钟

WARNING: 此操作将格式化Flash和EEPROM,但不会删除WiFi设置。它本质上是恢复出厂设置。

MQTT TopicHTTP URLPayload/BodyHTTP Method
N/Ahttp://[IP]/api/erase-POST

恢复初始设置

WARNING: 此操作将重置设置API中的所有设置。但不会重置Flash文件和WiFi设置。

MQTT TopicHTTP URLPayload/BodyHTTP Method
N/Ahttp://[IP]/api/resetSettings-POST