this is my int.lua
– Samsung Mini Split AC Edge Driver
-- Author: Ashwin
-- Date: August 12, 2025
local capabilities = require “st.capabilities”
local Driver = require “st.driver”
local log = require “log”
-- Driver constants
local DEVICE_PROFILE = “samsung-mini-split”
-- Initialize device with default attribute values
local function initialize_device(device)
log.info("Initializing Samsung Mini Split AC device: " .. device.device_network_id)
– airConditionerFanMode - Set default values as specified
device:emit_event(capabilities.airConditionerFanMode.fanMode(“medium”))
device:emit_event(capabilities.airConditionerFanMode.supportedAcFanModes({“auto”,“low”,“medium”,“high”,“turbo”}))
device:emit_event(capabilities.airConditionerFanMode.availableAcFanModes({“auto”,“low”,“medium”,“high”,“turbo”}))
– airConditionerMode - Set default values as specified for Lennox powered Samsung mini split
device:emit_event(capabilities.airConditionerMode.airConditionerMode(“cool”))
device:emit_event(capabilities.airConditionerMode.supportedAcModes({“auto”,“cool”,“dry”,“fan”,“heat”}))
device:emit_event(capabilities.airConditionerMode.availableAcModes({“auto”,“cool”,“dry”,“fan”,“heat”}))
– fanOscillationMode - Set default values as specified
device:emit_event(capabilities.fanOscillationMode.fanOscillationMode(“fixed”))
device:emit_event(capabilities.fanOscillationMode.supportedFanOscillationModes({“fixed”,“vertical”,“horizontal”,“all”}))
device:emit_event(capabilities.fanOscillationMode.availableFanOscillationModes({“fixed”,“vertical”,“horizontal”,“all”}))
– temperatureMeasurement - Set default temperature to 77°F
device:emit_event(capabilities.temperatureMeasurement.temperature({value = 77, unit = “F”}))
– thermostatCoolingSetpoint - Set default cooling setpoint and range
device:emit_event(capabilities.thermostatCoolingSetpoint.coolingSetpoint({value = 69, unit = “F”}))
device:emit_event(capabilities.thermostatCoolingSetpoint.coolingSetpointRange({minimum = 61, maximum = 86, step = 1, unit = “F”}))
– switch capability - default to off
device:emit_event(capabilities.switch.switch(“off”))
log.info(“Samsung Mini Split AC device initialized successfully”)
end
-- Handle device added
local function device_added(driver, device)
log.info("Device added: " .. device.device_network_id)
initialize_device(device)
end
-- Handle device initialization
local function device_init(driver, device)
log.info("Device init: " .. device.device_network_id)
initialize_device(device)
end
-- Handle driver initialization
local function driver_init(driver)
log.info(“Samsung Mini Split AC Driver initialized”)
log.info(“Driver capability handlers registered:”)
log.info("- Switch capability: " .. tostring(capabilities.switch.ID))
log.info("- AC Mode capability: " .. tostring(capabilities.airConditionerMode.ID))
log.info("- Cooling Setpoint capability: " .. tostring(capabilities.thermostatCoolingSetpoint.ID))
– Run discovery immediately when driver starts
discovery_handler(driver, {}, function() return false end)
end
-- Handle switch on command
local function handle_switch_on(driver, device, command)
log.info(“Handling switch on command”)
device:emit_event(capabilities.switch.switch(“on”))
– When turning on, ensure we have the proper AC mode and fan mode
device:emit_event(capabilities.airConditionerMode.airConditionerMode(“cool”))
device:emit_event(capabilities.airConditionerFanMode.fanMode(“medium”))
end
-- Handle switch off command
local function handle_switch_off(driver, device, command)
log.info(“Handling switch off command”)
device:emit_event(capabilities.switch.switch(“off”))
end
-- Handle air conditioner mode change for Lennox powered Samsung mini split
local function handle_ac_mode_change(driver, device, command)
local mode = command.args.mode
log.info("Changing AC mode to: " .. mode)
local supported_modes = {“auto”, “cool”, “dry”, “fan”, “heat”}
– Validate the mode
for _, supported_mode in ipairs(supported_modes) do
if supported_mode == mode then
device:emit_event(capabilities.airConditionerMode.airConditionerMode(mode))
-- If switching to a mode, ensure the unit is on
device:emit_event(capabilities.switch.switch("on"))
return
end
end
log.warn("Unsupported AC mode: " .. mode)
end
-- Handle fan mode change
local function handle_fan_mode_change(driver, device, command)
local fan_mode = command.args.fanMode
log.info("Changing fan mode to: " .. fan_mode)
local supported_fan_modes = {“auto”, “low”, “medium”, “high”, “turbo”}
– Validate the fan mode
for _, supported_mode in ipairs(supported_fan_modes) do
if supported_mode == fan_mode then
device:emit_event(capabilities.airConditionerFanMode.fanMode(fan_mode))
-- If changing fan mode, ensure the unit is on
device:emit_event(capabilities.switch.switch("on"))
return
end
end
log.warn("Unsupported fan mode: " .. fan_mode)
end
-- Handle fan oscillation mode change
local function handle_oscillation_mode_change(driver, device, command)
local oscillation_mode = command.args.fanOscillationMode
log.info("Changing oscillation mode to: " .. oscillation_mode)
local supported_oscillation_modes = {“fixed”, “vertical”, “horizontal”, “all”}
– Validate the oscillation mode
for _, supported_mode in ipairs(supported_oscillation_modes) do
if supported_mode == oscillation_mode then
device:emit_event(capabilities.fanOscillationMode.fanOscillationMode(oscillation_mode))
return
end
end
log.warn("Unsupported oscillation mode: " .. oscillation_mode)
end
-- Handle cooling setpoint change
local function handle_cooling_setpoint_change(driver, device, command)
log.info(“=== COOLING SETPOINT HANDLER CALLED ===”)
log.info("Command received: " .. (command and “YES” or “NO”))
log.info("Command args: " .. (command.args and “YES” or “NO”))
local setpoint = command.args.setpoint or command.args.value
log.info("Raw setpoint value: " .. tostring(setpoint))
log.info("Setpoint type: " .. type(setpoint))
log.info("Changing cooling setpoint to: " .. setpoint .. “°F”)
– Validate setpoint is within range (61-86°F)
if setpoint and setpoint >= 61 and setpoint <= 86 then
log.info("Setpoint is within valid range, emitting event...")
-- Try different emission formats
local temp_event = capabilities.thermostatCoolingSetpoint.coolingSetpoint({value = setpoint, unit = "F"})
log.info("Event object created: " .. tostring(temp_event))
device:emit_event(temp_event)
log.info("Cooling setpoint event emitted successfully")
-- Also try emitting without unit
device:emit_event(capabilities.thermostatCoolingSetpoint.coolingSetpoint(setpoint))
log.info("Alternative cooling setpoint event emitted")
-- If changing setpoint, ensure the unit is on and in cool mode
device:emit_event(capabilities.switch.switch("on"))
device:emit_event(capabilities.airConditionerMode.airConditionerMode("cool"))
log.info("Switch and AC mode events emitted")
else
log.warn("Setpoint out of range or missing: " .. tostring(setpoint) .. " (valid range: 61-86°F)")
end
log.info(“=== COOLING SETPOINT HANDLER COMPLETED ===”)
end
-- Handle refresh command
local function handle_refresh(driver, device, command)
log.info(“Refreshing device state”)
initialize_device(device)
end
-- Device discovery function
local function discovery_handler(driver, opts, should_continue)
log.info(“Starting Samsung Mini Split AC discovery”)
– Create a mock device for demonstration
– In a real implementation, this would scan for actual devices
local device_metadata = {
type = "LAN",
device_network_id = "samsung-mini-split-001",
label = "Samsung Mini Split AC",
profile = DEVICE_PROFILE,
manufacturer = "Samsung",
model = "Mini Split AC",
vendor_provided_label = "Samsung Mini Split Air Conditioner"
}
log.info("Creating Samsung Mini Split AC device with metadata: " .. device_metadata.device_network_id)
local device = driver:try_create_device(device_metadata)
if device then
log.info("Successfully created Samsung Mini Split AC device")
else
log.error("Failed to create Samsung Mini Split AC device")
end
end
-- Create the driver
local samsung_mini_split_driver = Driver(“SamsungMiniSplitDriver”, {
discovery = discovery_handler,
lifecycle_handlers = {
init = driver_init,
added = device_added,
driverSwitched = device_init
},
capability_handlers = {
\[capabilities.switch.ID\] = {
\[capabilities.switch.commands.on.NAME\] = handle_switch_on,
\[capabilities.switch.commands.off.NAME\] = handle_switch_off
},
\[capabilities.airConditionerMode.ID\] = {
\[capabilities.airConditionerMode.commands.setAirConditionerMode.NAME\] = handle_ac_mode_change
},
\[capabilities.airConditionerFanMode.ID\] = {
\[capabilities.airConditionerFanMode.commands.setFanMode.NAME\] = handle_fan_mode_change
},
\[capabilities.fanOscillationMode.ID\] = {
\[capabilities.fanOscillationMode.commands.setFanOscillationMode.NAME\] = handle_oscillation_mode_change
},
\[capabilities.thermostatCoolingSetpoint.ID\] = {
\[capabilities.thermostatCoolingSetpoint.commands.setCoolingSetpoint.NAME\] = handle_cooling_setpoint_change
},
\[capabilities.refresh.ID\] = {
\[capabilities.refresh.commands.refresh.NAME\] = handle_refresh
}
}
})
-- Run the driver
samsung_mini_split_driver:run()