Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions drivers/SmartThings/matter-sensor/fingerprints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@ matterManufacturer:
vendorId: 0x134E
productId: 0x0006
deviceProfileName: temperature-humidity
#ThingsOne
- id: "4673/32784"
deviceLabel: ThingsOne Presence Sensor
vendorId: 0x1241
productId: 0x8010
deviceProfileName: thingsone-presence-sensor
#Tuo
- id: "5150/3"
deviceLabel: "TUO Temperature Sensor"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: thingsone-presence-sensor
components:
- id: main
capabilities:
- id: presenceSensor
version: 1
- id: temperatureMeasurement
version: 1
- id: relativeHumidityMeasurement
version: 1
- id: illuminanceMeasurement
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: PresenceSensor
preferences:
- preferenceId: tempOffset
explicit: true
- preferenceId: humidityOffset
explicit: true
- preferenceId: stse.presenceHoldTime
explicit: true
3 changes: 3 additions & 0 deletions drivers/SmartThings/matter-sensor/src/sensor_utils/fields.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ SensorFields.BOOLEAN_CAP_EVENT_MAP = {
SensorFields.vendor_overrides = {
[0x115F] = { -- AQARA_MANUFACTURER_ID
[0x2009] = { is_aqara_fp400 = true }
},
[0x1241] = { -- SAMJIN_MANUFACTURER_ID
[0x8010] = { is_thingsone_presence_sensor = true }
}
}

Expand Down
1 change: 1 addition & 0 deletions drivers/SmartThings/matter-sensor/src/sub_drivers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ local sub_drivers = {
lazy_load_if_possible("sub_drivers.smoke_co_alarm"),
lazy_load_if_possible("sub_drivers.bosch_button_contact"),
lazy_load_if_possible("sub_drivers.aqara_fp400"),
lazy_load_if_possible("sub_drivers.thingsone_presence_sensor"),
}
return sub_drivers
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- Copyright 2026 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0

local function is_thingsone_presence_sensor(opts, driver, device)
local sensor_utils = require "sensor_utils.utils"
if sensor_utils.get_product_override_field(device, "is_thingsone_presence_sensor") then
return true, require("sub_drivers.thingsone_presence_sensor")
end
return false
end

return is_thingsone_presence_sensor
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
-- Copyright 2026 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0

local clusters = require "st.matter.clusters"
local st_utils = require "st.utils"
local version = require "version"

local PROFILE = "thingsone-presence-sensor"
local PRESENCE_HOLD_TIME = "stse.presenceHoldTime"

-- HoldTime is the device's shipped 20 s (a 10 s rest after motion, then 10 s of radar check that each radar detection restarts) plus the presence hold time; 280 keeps it within HoldTimeLimits 1..300
local function write_presence_hold_time(device, preference)
local seconds = tonumber(preference)
local ep = device:get_endpoints(clusters.OccupancySensing.ID)[1]
if seconds == nil or ep == nil then
return
end
seconds = st_utils.clamp_value(math.floor(seconds), 0, 280)
device:send(clusters.OccupancySensing.attributes.HoldTime:write(device, ep, 20 + seconds))
end

local ThingsOneLifecycleHandlers = {}

-- Keeps the base driver from re-matching the device to a profile without the presence hold time setting
function ThingsOneLifecycleHandlers.do_configure(driver, device)
device:try_update_metadata({profile = PROFILE})
end

function ThingsOneLifecycleHandlers.driver_switched(driver, device)
device:try_update_metadata({profile = PROFILE})
device:try_update_metadata({provisioning_state = "PROVISIONED"})
end

function ThingsOneLifecycleHandlers.info_changed(driver, device, event, args)
if device.profile.id ~= args.old_st_store.profile.id then
device:subscribe()
end
local old = args.old_st_store.preferences or {}
local new = device.preferences or {}
if new[PRESENCE_HOLD_TIME] ~= nil and new[PRESENCE_HOLD_TIME] ~= old[PRESENCE_HOLD_TIME] then
-- HoldTime comes with lua libs api 13 (OccupancySensing revision 5); on older libs even looking it up raises an error
if version.api >= 13 then
write_presence_hold_time(device, new[PRESENCE_HOLD_TIME])
else
device.log.warn("OccupancySensing.HoldTime needs lua libs api 13; the presence hold time setting has no effect")
end
end
end

local thingsone_presence_sensor_handler = {
NAME = "thingsone-presence-sensor",
lifecycle_handlers = {
doConfigure = ThingsOneLifecycleHandlers.do_configure,
driverSwitched = ThingsOneLifecycleHandlers.driver_switched,
infoChanged = ThingsOneLifecycleHandlers.info_changed,
},
can_handle = require("sub_drivers.thingsone_presence_sensor.can_handle"),
}

return thingsone_presence_sensor_handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
-- Copyright 2026 SmartThings, Inc.
-- Licensed under the Apache License, Version 2.0

local test = require "integration_test"
local capabilities = require "st.capabilities"
local clusters = require "st.matter.clusters"
local t_utils = require "integration_test.utils"
local version = require "version"

-- HoldTime and the OccupancySensing features come with lua libs api 13; on older libs even looking them up raises
-- an error, so they are only looked up from api 13 and the HoldTime tests set min_api_version = 13
local HOLD_TIME = version.api >= 13 and clusters.OccupancySensing.attributes.HoldTime or nil
local OCCUPANCY_FEATURES = 0
if version.api >= 13 then
OCCUPANCY_FEATURES = clusters.OccupancySensing.types.Feature.PASSIVE_INFRARED | clusters.OccupancySensing.types.Feature.RADAR
end

-- Endpoint and cluster layout of the device firmware
local matter_endpoints = {
{
endpoint_id = 0,
clusters = {
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"},
{cluster_id = clusters.PowerSource.ID, cluster_type = "SERVER", feature_map = clusters.PowerSource.types.PowerSourceFeature.BATTERY},
},
device_types = {
{device_type_id = 0x0016, device_type_revision = 1}, -- RootNode
{device_type_id = 0x0011, device_type_revision = 1} -- PowerSource
}
},
{
endpoint_id = 1,
clusters = {
{
cluster_id = clusters.OccupancySensing.ID,
cluster_type = "SERVER",
feature_map = OCCUPANCY_FEATURES
},
},
device_types = {
{device_type_id = 0x0107, device_type_revision = 1} -- OccupancySensor
}
},
{
endpoint_id = 2,
clusters = {
{cluster_id = clusters.TemperatureMeasurement.ID, cluster_type = "SERVER"},
},
device_types = {
{device_type_id = 0x0302, device_type_revision = 1} -- TemperatureSensor
}
},
{
endpoint_id = 3,
clusters = {
{cluster_id = clusters.IlluminanceMeasurement.ID, cluster_type = "SERVER"},
},
device_types = {
{device_type_id = 0x0106, device_type_revision = 1} -- LightSensor
}
},
{
endpoint_id = 4,
clusters = {
{cluster_id = clusters.RelativeHumidityMeasurement.ID, cluster_type = "SERVER"},
},
device_types = {
{device_type_id = 0x0307, device_type_revision = 1} -- HumiditySensor
}
},
}

local mock_device = test.mock_device.build_test_matter_device({
profile = t_utils.get_profile_definition("thingsone-presence-sensor.yml"),
manufacturer_info = {vendor_id = 0x1241, product_id = 0x8010},
endpoints = matter_endpoints
})

local function subscribe_request(dev)
local request = clusters.OccupancySensing.attributes.Occupancy:subscribe(dev)
request:merge(clusters.TemperatureMeasurement.attributes.MeasuredValue:subscribe(dev))
request:merge(clusters.TemperatureMeasurement.attributes.MinMeasuredValue:subscribe(dev))
request:merge(clusters.TemperatureMeasurement.attributes.MaxMeasuredValue:subscribe(dev))
request:merge(clusters.IlluminanceMeasurement.attributes.MeasuredValue:subscribe(dev))
request:merge(clusters.RelativeHumidityMeasurement.attributes.MeasuredValue:subscribe(dev))
request:merge(clusters.PowerSource.attributes.BatPercentRemaining:subscribe(dev))
return request
end

local function test_init()
test.socket.matter:__expect_send({mock_device.id, subscribe_request(mock_device)})
test.mock_device.add_test_device(mock_device)
end
test.set_test_init_function(test_init)

local function preference(id, value)
return mock_device:generate_info_changed({preferences = {[id] = value}})
end

local function expect_write(attr, value)
test.socket.matter:__expect_send({mock_device.id, attr:write(mock_device, 1, value)})
end

local function report(attr, value)
return {mock_device.id, attr:build_test_report_data(mock_device, 1, value)}
end

test.register_coroutine_test(
"doConfigure should keep the ThingsOne profile instead of reading the PowerSource AttributeList",
function()
test.socket.device_lifecycle:__queue_receive({mock_device.id, "doConfigure"})
mock_device:expect_metadata_update({profile = "thingsone-presence-sensor"})
-- When doConfigure completes successfully, the framework automatically provisions the device
mock_device:expect_metadata_update({provisioning_state = "PROVISIONED"})
test.wait_for_events()
end
)

test.register_coroutine_test(
"driverSwitched should set the ThingsOne profile and provision the device",
function()
test.socket.device_lifecycle:__queue_receive({mock_device.id, "driverSwitched"})
mock_device:expect_metadata_update({profile = "thingsone-presence-sensor"})
mock_device:expect_metadata_update({provisioning_state = "PROVISIONED"})
test.wait_for_events()
end
)

test.register_coroutine_test(
"A profile change should renew the subscription",
function()
test.socket.device_lifecycle:__queue_receive(mock_device:generate_info_changed({profile = {id = "00000000-1111-2222-3333-000000000004"}}))
test.socket.matter:__expect_send({mock_device.id, subscribe_request(mock_device)})
test.wait_for_events()
end
)

test.register_message_test(
"Occupancy reports should be passed on at once by the base driver",
{
{
channel = "matter",
direction = "receive",
message = report(clusters.OccupancySensing.attributes.Occupancy, 1)
},
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.presenceSensor.presence("present"))
},
{
channel = "matter",
direction = "receive",
message = report(clusters.OccupancySensing.attributes.Occupancy, 0)
},
{
channel = "capability",
direction = "send",
message = mock_device:generate_test_message("main", capabilities.presenceSensor.presence("not present"))
}
}
)

test.register_coroutine_test(
"Offset changes should send nothing to the device, the platform applies the offsets",
function()
test.socket.device_lifecycle:__queue_receive(preference("tempOffset", "1"))
test.wait_for_events()
test.socket.device_lifecycle:__queue_receive(preference("humidityOffset", "-3"))
test.wait_for_events()
end
)

test.register_coroutine_test(
"Every presence hold time option should write HoldTime as 20 s plus the option on EP1",
function()
-- stse.presenceHoldTime is an enumeration of these strings, each paired with the HoldTime it writes; the default "0"
-- comes last so that every step is a change
local options = {{"5", 25}, {"10", 30}, {"15", 35}, {"30", 50}, {"60", 80}, {"0", 20}}
for _, option in ipairs(options) do
test.socket.device_lifecycle:__queue_receive(preference("stse.presenceHoldTime", option[1]))
expect_write(HOLD_TIME, option[2])
test.wait_for_events()
end
end,
{
min_api_version = 13
}
)

test.register_coroutine_test(
"A first choice of the default presence hold time of 0 should write HoldTime 20, and an unchanged one should not",
function()
test.socket.device_lifecycle:__queue_receive(preference("stse.presenceHoldTime", "0"))
expect_write(HOLD_TIME, 20)
test.wait_for_events()
test.socket.device_lifecycle:__queue_receive(preference("stse.presenceHoldTime", "0"))
test.wait_for_events()
end,
{
min_api_version = 13
}
)

-- The app offers only the options above; the next two tests cover the guards for any other value
test.register_coroutine_test(
"A numeric or fractional presence hold time should be written as whole seconds",
function()
test.socket.device_lifecycle:__queue_receive(preference("stse.presenceHoldTime", 15))
expect_write(HOLD_TIME, 35)
test.wait_for_events()
test.socket.device_lifecycle:__queue_receive(preference("stse.presenceHoldTime", 30.0))
expect_write(HOLD_TIME, 50)
test.wait_for_events()
end,
{
min_api_version = 13
}
)

test.register_coroutine_test(
"A presence hold time outside 0..280 s should be clamped so HoldTime stays within 20..300 s",
function()
test.socket.device_lifecycle:__queue_receive(preference("stse.presenceHoldTime", "600"))
expect_write(HOLD_TIME, 300)
test.wait_for_events()
test.socket.device_lifecycle:__queue_receive(preference("stse.presenceHoldTime", "-5"))
expect_write(HOLD_TIME, 20)
test.wait_for_events()
end,
{
min_api_version = 13
}
)

test.run_registered_tests()