return {
    active = true,
    
    on = {
        devices = {
            'Steam - Username Status'
        }
    },

    logging = {
        level = domoticz.LOG_INFO,
        marker = "AWTRIX3_STEAM"
    },

    execute = function(domoticz, steamStatus)
        -- Check the new state of the "Steam Status" switch
        local newState = steamStatus.state
        domoticz.log("Steam Status changed to: " .. newState, domoticz.LOG_INFO)

        -- Define default text and icon
        local notificationText = ""
        local notificationIcon = 28166 -- Fixed icon ID for all states

        if newState == "In-Game" then
            local gameNameDevice = domoticz.devices('Steam - Username Game Name')
            if gameNameDevice and gameNameDevice.text and gameNameDevice.text ~= "" then
                notificationText = "Playing: " .. gameNameDevice.text
                domoticz.log("Fetched game name: " .. gameNameDevice.text, domoticz.LOG_INFO)
            else
                notificationText = "In-game"
                domoticz.log("No game name found in Steam Game Name device", domoticz.LOG_WARNING)
            end
        elseif newState == "Online" then
            notificationText = "Online"
        elseif newState == "Offline" then
            notificationText = "Offline"
        else
            domoticz.log("Unhandled state: " .. newState, domoticz.LOG_WARNING)
            return
        end

        -- Format the JSON payload for AWTRIX3
        local payload = {
            text = notificationText,
            icon = notificationIcon
        }
        local payloadJSON = domoticz.utils.toJSON(payload)

        domoticz.log("Sending to AWTRIX3: " .. payloadJSON, domoticz.LOG_INFO)

        -- Send the JSON to the AWTRIX3 "Send Notification App" device
        local awtrixDevice = domoticz.devices('AWTRIX3 - Send Notification')
        if awtrixDevice then
            awtrixDevice.setDescription(payloadJSON)
            awtrixDevice.switchOn().afterSec(2)
        else
            domoticz.log("AWTRIX3 - Send Notification device not found", domoticz.LOG_ERROR)
        end
    end
}