Skip to content

Commit

Permalink
Support the tilt feature
Browse files Browse the repository at this point in the history
  • Loading branch information
nickolas-deboom committed Dec 10, 2024
1 parent 1b84fa9 commit 8264136
Show file tree
Hide file tree
Showing 6 changed files with 333 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: window-covering-tilt-battery
components:
- id: main
capabilities:
- id: windowShade
version: 1
- id: windowShadePreset
version: 1
- id: windowShadeLevel
version: 1
- id: windowShadeTiltLevel
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: Blind
preferences:
- preferenceId: presetPosition
explicit: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: window-covering-tilt-only-battery
components:
- id: main
capabilities:
- id: windowShade
version: 1
- id: windowShadePreset
version: 1
- id: windowShadeTiltLevel
version: 1
- id: battery
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: Blind
preferences:
- preferenceId: presetPosition
explicit: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: window-covering-tilt-only
components:
- id: main
capabilities:
- id: windowShade
version: 1
- id: windowShadePreset
version: 1
- id: windowShadeTiltLevel
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: Blind
preferences:
- preferenceId: presetPosition
explicit: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: window-covering-tilt
components:
- id: main
capabilities:
- id: windowShade
version: 1
- id: windowShadePreset
version: 1
- id: windowShadeLevel
version: 1
- id: windowShadeTiltLevel
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: Blind
preferences:
- preferenceId: presetPosition
explicit: true
69 changes: 49 additions & 20 deletions drivers/SmartThings/matter-window-covering/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ end

local function match_profile(device)
local profile_name = "window-covering"
local lift_eps = device:get_endpoints(clusters.WindowCovering.ID, {feature_bitmap = clusters.WindowCovering.types.Feature.LIFT})
local tilt_eps = device:get_endpoints(clusters.WindowCovering.ID, {feature_bitmap = clusters.WindowCovering.types.Feature.TILT})
if #tilt_eps > 0 then
if #lift_eps > 0 then
profile_name = profile_name .. "-tilt"
else
profile_name = profile_name .. "-tilt-only"
end
end
local battery_eps = device:get_endpoints(clusters.PowerSource.ID,
{feature_bitmap = clusters.PowerSource.types.PowerSourceFeature.BATTERY})

Expand Down Expand Up @@ -111,8 +120,7 @@ local function handle_pause(driver, device, cmd)
device:send(req)
end

-- move to shade level
-- beteween 0-100
-- move to shade level between 0-100
local function handle_shade_level(driver, device, cmd)
local endpoint_id = device:component_to_endpoint(cmd.component)
local lift_percentage_value = 100 - cmd.args.shadeLevel
Expand All @@ -123,29 +131,42 @@ local function handle_shade_level(driver, device, cmd)
device:send(req)
end

-- current lift percentage, changed to 100ths percent
local function current_pos_handler(driver, device, ib, response)
if ib.data.value == nil then
return
end
local windowShade = capabilities.windowShade.windowShade
local position = 100 - math.floor((ib.data.value / 100))
device:emit_event_for_endpoint(ib.endpoint_id, capabilities.windowShadeLevel.shadeLevel(position))
if position == 0 then
device:emit_event_for_endpoint(ib.endpoint_id, windowShade.closed())
elseif position == 100 then
device:emit_event_for_endpoint(ib.endpoint_id, windowShade.open())
elseif position > 0 and position < 100 then
device:emit_event_for_endpoint(ib.endpoint_id, windowShade.partially_open())
else
device:emit_event_for_endpoint(ib.endpoint_id, windowShade.unknown())
-- move to shade tilt level between 0-100
local function handle_shade_tilt_level(driver, device, cmd)
local endpoint_id = device:component_to_endpoint(cmd.component)
local tilt_percentage_value = 100 - cmd.args.level
local hundredths_tilt_percentage = tilt_percentage_value * 100
local req = clusters.WindowCovering.server.commands.GoToTiltPercentage(
device, endpoint_id, hundredths_tilt_percentage
)
device:send(req)
end

-- current lift/tilt percentage, changed to 100ths percent
local current_pos_handler = function(attribute)
return function(driver, device, ib, response)
if ib.data.value == nil then
return
end
local windowShade = capabilities.windowShade.windowShade
local position = 100 - math.floor((ib.data.value / 100))
device:emit_event_for_endpoint(ib.endpoint_id, attribute(position))
if position == 0 then
device:emit_event_for_endpoint(ib.endpoint_id, windowShade.closed())
elseif position == 100 then
device:emit_event_for_endpoint(ib.endpoint_id, windowShade.open())
elseif position > 0 and position < 100 then
device:emit_event_for_endpoint(ib.endpoint_id, windowShade.partially_open())
else
device:emit_event_for_endpoint(ib.endpoint_id, windowShade.unknown())
end
end
end

-- checks the current position of the shade
local function current_status_handler(driver, device, ib, response)
local windowShade = capabilities.windowShade.windowShade
local state = ib.data.value & clusters.WindowCovering.types.OperationalStatus.GLOBAL --Could use LIFT instead
local state = ib.data.value & clusters.WindowCovering.types.OperationalStatus.GLOBAL
if state == 1 then -- opening
device:emit_event_for_endpoint(ib.endpoint_id, windowShade.opening())
elseif state == 2 then -- closing
Expand Down Expand Up @@ -180,7 +201,8 @@ local matter_driver_template = {
},
[clusters.WindowCovering.ID] = {
--uses percent100ths more often
[clusters.WindowCovering.attributes.CurrentPositionLiftPercent100ths.ID] = current_pos_handler,
[clusters.WindowCovering.attributes.CurrentPositionLiftPercent100ths.ID] = current_pos_handler(capabilities.windowShadeLevel.shadeLevel),
[clusters.WindowCovering.attributes.CurrentPositionTiltPercent100ths.ID] = current_pos_handler(capabilities.windowShadeTiltLevel.shadeTiltLevel),
[clusters.WindowCovering.attributes.OperationalStatus.ID] = current_status_handler,
},
[clusters.PowerSource.ID] = {
Expand All @@ -196,6 +218,9 @@ local matter_driver_template = {
clusters.LevelControl.attributes.CurrentLevel,
clusters.WindowCovering.attributes.CurrentPositionLiftPercent100ths,
},
[capabilities.windowShadeTiltLevel.ID] = {
clusters.WindowCovering.attributes.CurrentPositionTiltPercent100ths,
},
[capabilities.battery.ID] = {
clusters.PowerSource.attributes.BatPercentRemaining
}
Expand All @@ -215,9 +240,13 @@ local matter_driver_template = {
[capabilities.windowShadeLevel.ID] = {
[capabilities.windowShadeLevel.commands.setShadeLevel.NAME] = handle_shade_level,
},
[capabilities.windowShadeTiltLevel.ID] = {
[capabilities.windowShadeTiltLevel.commands.setShadeTiltLevel.NAME] = handle_shade_tilt_level,
},
},
supported_capabilities = {
capabilities.windowShadeLevel,
capabilities.windowShadeTiltLevel,
capabilities.windowShade,
capabilities.windowShadePreset,
capabilities.battery,
Expand Down
Loading

0 comments on commit 8264136

Please sign in to comment.