Skip to main content

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​

  1. Device access
  2. Device information queries
  3. Device control
  4. System information
  5. Weather service
  6. Utility scripts

1. Device Access​

Access devices through path IDs in the form $PAGENAME.IDX.

Current page names:

Page nameDescriptionIDX range
NM_HOMEHome page1..16
NM_SCENEScene page1..16
NM_SCENE2Extended scene page1..16
NM_SCENE3Extended scene page1..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​

cgyDescriptionAvailable fields
epDevice objectAll IO data under the device
ioIO object (a device function point)vidx, type, val, rv
aiAutomation/scene objectstat (AI state)

3. Device Control​

svcreq("epctl", command)​

Unified interface for device control.

Command format: json:path:cmd

cmd Options​

cmdDescription
clickClick: toggle switches; open device pages for devices/sensors
onTurn on
offTurn off
set[sw=1 type=0x81 val=50]Set an analog value. sw=switch (0/1); type/val are optional
selbindOpen 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:

FieldTypeDescription
temperaturenumberCurrent temperature (℃)
humiditynumberCurrent humidity (0~1)
skyconstringWeather condition code
aqinumberAir quality index
pm25numberPM2.5 value
windstringWind direction and speed
pressurenumberAir pressure
queryCitytableCity information (city, lat, lng, distance)
nextHourstableHourly 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.

ParameterDescription
pathCorresponding scene (e.g. $NM_HOME.1)
cmdButton command (click/on/off/set[...]/selbind; may also be a function called on triggering)
idxButton number (starting at 1)
flag0=allow page swiping; 1=disallow (NatureMiniPro firmware behavior)
x, y, x2, y2Hot-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)
kvCustom 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.

ParameterDescription
dotriggertrue = execute the defined cmd
ReturnDescription
hotidxNumber of the button under the touch
triggerWhether an action was triggered

Return count depends on the included colox_mini.lua version: newer versions return six values, hotidx, trigger, rectidx, mx, my, mb (rectidx distinguishes hits on multiple rectangles). Objects also support dragcb (drag callback) and userelease (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:

FunctionDescription
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:

ParameterDescription
idIdentifier for lookup
zDrawing order among siblings (lower values first)
x, yCoordinates relative to the parent
txtText to draw
imgImage object
anchDrawing anchor (bit0=alpha blending, bit1-2=X anchor, bit3-4=Y anchor)
outlinecolOutline color