NatureMiniPro Service Extensions
NatureMiniPro provides device control and display extensions for home/scene/device page interactions.
Limit: Home and scene pages each support at most 16 device or IO objects. A device page corresponds to one device object only.
Application interfaces can replace the home or scene page, querying and controlling the original page's device objects through service interfaces.
Contents
- Device access
- Device information queries
- Device control
- System information
- Weather service
- Utility scripts
1. Device Access
Access devices through path IDs in the form $PAGENAME.IDX.
Current page names:
| Page name | Description | IDX range |
|---|---|---|
NM_HOME | Home page | 1..16 |
NM_SCENE | Scene page | 1..16 |
NM_SCENE2 | Extended scene page | 1..16 |
NM_SCENE3 | Extended scene page | 1..16 |
Get the current UI page position with stat(6):
local path = stat(6) or 'NM_HOME'
if path == 'SS' then
printh('screen saver')
elseif path == 'NM_HOME' then
printh('Home page')
elseif path == 'NM_SCENE' then
printh('Scene page 1')
elseif path == 'NM_SCENE2' then
printh('Scene page 2')
else
print(path)
end
2. Device Information Queries
svcget(path)
Queries device information, returning a table or nil.
local obj = svcget('$NM_HOME.1')
if type(obj) == 'table' then
printh(obj.cgy) -- Object category
printh(obj.cls) -- Detailed specification
printh(obj.name) -- Name (may be empty)
if obj.cgy == 'io' then
printh(obj.type & 1) -- IO type
elseif obj.cgy == 'ai' then
printh(obj.stat) -- AI state
end
end
Object Types
| cgy | Description | Available fields |
|---|---|---|
ep | Device object | All IO data under the device |
io | IO object (a device function point) | vidx, type, val, rv |
ai | Automation/scene object | stat (AI state) |
3. Device Control
svcreq("epctl", command)
Unified interface for device control.
Command format: json:path:cmd
cmd Options
| cmd | Description |
|---|---|
click | Click: toggle switches; open device pages for devices/sensors |
on | Turn on |
off | Turn off |
set[sw=1 type=0x81 val=50] | Set an analog value. sw=switch (0/1); type/val are optional |
selbind | Open the interface for rebinding the device object |
-- Turn on the first scene device (a dimmable light) at 50% brightness
svcreq("epctl", "json:$NM_SCENE.1:set[sw=1 val=127]")
-- Control the third virtual button of the second scene device (AIB)
svcreq("epctl", "json:$NM_SCENE.2:aib[bt=3]")
-- Toggle the first device on the home page
svcreq("epctl", "json:$NM_HOME.1:click")
Opening the Main Menu
svcreq("epctl", "json:openmenu")
4. System Information
Getting Device Type
svcget('$sys.model') -- NatureMiniPro returns 'LSNAMIV3'
Getting Language Settings
local lang = svcget('$sys.lang') -- 1=English, 2=Chinese
Getting Device Temperature
local temp = svcget('$sc.T') -- Temperature in Celsius, floating-point
5. Weather Service
svcget('$weather.cur')
Queries the forecast, returning a table containing:
| Field | Type | Description |
|---|---|---|
temperature | number | Current temperature (℃) |
humidity | number | Current humidity (0~1) |
skycon | string | Weather condition code |
aqi | number | Air quality index |
pm25 | number | PM2.5 value |
wind | string | Wind direction and speed |
pressure | number | Air pressure |
queryCity | table | City information (city, lat, lng, distance) |
nextHours | table | Hourly forecast array |
skycon weather codes: CLEAR_DAY, CLEAR_NIGHT, PARTLY_CLOUDY_DAY, PARTLY_CLOUDY_NIGHT, CLOUDY, LIGHT_HAZE, MODERATE_HAZE, HEAVY_HAZE, RAIN, LIGHT_RAIN, MODERATE_RAIN, HEAVY_RAIN, STORM_RAIN, FOG, LIGHT_SNOW, MODERATE_SNOW, HEAVY_SNOW, STORM_SNOW, DUST, SAND, WIND
6. Utility Scripts
colox_mini.lua — Scene Control
Convenient tools for controlling LifeSmart scenes.
#include colox_mini.lua
mini:add_touch(path, cmd, idx, flag, x, y, x2, y2, kv)
Defines a button region.
| Parameter | Description |
|---|---|
path | Corresponding scene (e.g. $NM_HOME.1) |
cmd | Button command (click/on/off/set[...]/selbind; may also be a function called on triggering) |
idx | Button number (starting at 1) |
flag | 0=allow page swiping; 1=disallow (NatureMiniPro firmware behavior) |
x, y, x2, y2 | Hot-zone rectangle. If x is an array of rectangles {{x1,y1,x2,y2}, ...}, registers multiple rectangle hot zones (scantouch returns rectidx to identify the hit rectangle) |
kv | Custom data table |
local mini = cx_mini_init()
mini:add_touch('$NM_HOME.1', nil, 1, 0, 309, 180, 480, 480)
mini:add_touch('$NM_HOME.2', nil, 2, 0, 0, 0, 480, 232)
mini:add_touch('$NM_HOME.3', nil, 3, 0, 0, 230, 306, 480)
hotidx, trigger = mini:scantouch(dotrigger)
Handles button operations.
| Parameter | Description |
|---|---|
dotrigger | true = execute the defined cmd |
| Return | Description |
|---|---|
hotidx | Number of the button under the touch |
trigger | Whether an action was triggered |
Return count depends on the included
colox_mini.luaversion: newer versions return six values,hotidx, trigger, rectidx, mx, my, mb(rectidxdistinguishes hits on multiple rectangles). Objects also supportdragcb(drag callback) anduserelease(trigger on release).
local hotidx, trigger = mini:scantouch(true)
Complete Example
#include colox_mini.lua
local mini = cx_mini_init()
mini:add_touch('$NM_HOME.1', 'click', 1, 0, 30, 100, 200, 200)
function _draw()
cls()
local hotidx, trigger = mini:scantouch(true)
for k, v in pairs(mini.mini_objs) do
local info = mini:get_info(k)
if info then
if info.sw then
rectfill(v[3], v[4], v[5], v[6], red) -- On state
else
rectfill(v[3], v[4], v[5], v[6], blue) -- Off state
end
else
rectfill(v[3], v[4], v[5], v[6], orange) -- Invalid state
end
end
end
colox_layer.lua — Layered Image Drawing
Provides a tree-structured drawing hierarchy.
Features:
- Tree-structured drawing nodes (layers) for backgrounds/buttons/decorative images
- Each layer uses relative coordinates
- Drawing follows layer order, with individual layer visibility control
- Layer data can be modified dynamically
Creating Layers:
| Function | Description |
|---|---|
CXLAYER(id, z, x, y) | Logical layer (no actual drawing) |
CXLAYER_LABEL(id, z, txt, x, y, col, opt, size, fname, outlinecol) | Text drawing |
CXLAYER_IMG(id, z, x, y, img, anch, sx, sy, sw, sh) | Image drawing |
CXLAYER_ROT(id, z, x, y, sprx, spry, sprw, sprh, angle, zoomx, zoomy) | Rotation/scaling drawing |
Common parameters:
| Parameter | Description |
|---|---|
id | Identifier for lookup |
z | Drawing order among siblings (lower values first) |
x, y | Coordinates relative to the parent |
txt | Text to draw |
img | Image object |
anch | Drawing anchor (bit0=alpha blending, bit1-2=X anchor, bit3-4=Y anchor) |
outlinecol | Outline color |